/*
*******************************************************************************
** Copyright (C), 2014-2020, TONLY AV R&D CENTER SOFTWARE DEVELOPMENT DEPARTMENT
** FileName: 
** <author>:             
** Date:
** Description:
**
** Others:
** Function List:
**   1.
** History:
**  <Author>    <date>    <content>    <version>
*******************************************************************************
*/
/*******************************************************************************
 * file include
*******************************************************************************/
#include "cdn_pwm.h"
#include "sl_pwm.h"
#include "sl_pwm_instances.h"
#include "app_log.h"
#include "input_mesh.h"
#include "cdn_light.h"

extern LightInfo CdnLightNode;

/*******************************************************************************
 * global data
*******************************************************************************/
#if CDN_LIGHT_BULB
#if ZZX_Test   //用于调光600Hz,调色3.2KHz
//筒灯曲线调光
const uint32_t cdn_pwm_duty[DIM_MAX_VALUE_INDEX] =
{
    0 ,
    1234 ,1249 ,1264 ,1279 ,1295 ,1310 ,1326 ,1342 ,1357 ,1373 ,1389 ,1406 ,1422 ,1438 ,1455 ,1472 ,1489 ,1505 ,1523 ,1540 ,1557 ,1574 ,1592 ,1610 ,1627 ,
    1645 ,1663 ,1682 ,1700 ,1718 ,1737 ,1756 ,1775 ,1793 ,1813 ,1832 ,1851 ,1871 ,1890 ,1910 ,1930 ,1950 ,1970 ,1990 ,2011 ,2031 ,2052 ,2073 ,2094 ,2115 ,
    2136 ,2157 ,2179 ,2200 ,2222 ,2244 ,2266 ,2288 ,2311 ,2333 ,2356 ,2378 ,2401 ,2424 ,2447 ,2471 ,2494 ,2518 ,2541 ,2565 ,2589 ,2614 ,2638 ,2662 ,2687 ,
    2712 ,2736 ,2762 ,2787 ,2812 ,2837 ,2863 ,2889 ,2915 ,2941 ,2967 ,2993 ,3020 ,3047 ,3073 ,3100 ,3128 ,3155 ,3182 ,3210 ,3238 ,3265 ,3293 ,3322 ,3350 ,
    3378 ,3407 ,3436 ,3465 ,3494 ,3523 ,3553 ,3582 ,3612 ,3642 ,3672 ,3702 ,3733 ,3763 ,3794 ,3825 ,3856 ,3887 ,3918 ,3950 ,3982 ,4014 ,4046 ,4078 ,4110 ,
    4143 ,4175 ,4208 ,4241 ,4274 ,4307 ,4341 ,4375 ,4408 ,4442 ,4477 ,4511 ,4545 ,4580 ,4615 ,4650 ,4685 ,4721 ,4756 ,4792 ,4828 ,4864 ,4900 ,4936 ,4973 ,
    5009 ,5046 ,5083 ,5121 ,5158 ,5196 ,5234 ,5271 ,5310 ,5348 ,5386 ,5425 ,5464 ,5503 ,5542 ,5582 ,5621 ,5661 ,5701 ,5741 ,5781 ,5822 ,5862 ,5903 ,5944 ,
    5985 ,6027 ,6068 ,6110 ,6152 ,6194 ,6236 ,6279 ,6321 ,6364 ,6407 ,6450 ,6494 ,6537 ,6581 ,6625 ,6669 ,6714 ,6758 ,6803 ,6848 ,6893 ,6938 ,6984 ,7029 ,
    7075 ,7121 ,7168 ,7214 ,7261 ,7307 ,7354 ,7402 ,7449 ,7497 ,7545 ,7593 ,7641 ,7689 ,7738 ,7786 ,7835 ,7885 ,7934 ,7984 ,8033 ,8083 ,8134 ,8184 ,8234 ,
    8285 ,8336 ,8387 ,8439 ,8490 ,8542 ,8594 ,8646 ,8699 ,8751 ,8804 ,8857 ,8910 ,8964 ,9017 ,9071 ,9125 ,9179 ,9234 ,9289 ,9343 ,9398 ,9454 ,9509 ,9565 ,
    9621 ,9677 ,9733 ,9790 ,9846 ,9903 ,9961 ,10018 ,10076 ,10133 ,10191 ,10250 ,10308 ,10367 ,10426 ,10485 ,10544 ,10603 ,10663 ,10723 ,10783 ,10844 ,10904 ,10965 ,11026 ,
    11087 ,11149 ,11210 ,11272 ,11334 ,11397 ,11459 ,11522 ,11585 ,11648 ,11712 ,11775 ,11839 ,11903 ,11968 ,12032 ,12097 ,12162 ,12227 ,12293 ,12358 ,12424 ,12490 ,12557 ,
    12623 ,12690 ,12757 ,12825 ,12892 ,12960 ,13028 ,13096 ,13164 ,13233 ,13302 ,13371 ,13440 ,13510 ,13579 ,13649 ,13720 ,13790 ,13861 ,13932 ,14003 ,14074 ,14146 ,14218 ,
    14290 ,14362 ,14435 ,14508 ,14581 ,14654 ,14728 ,14801 ,14875 ,14950 ,15024 ,15099 ,15174 ,15249 ,15324 ,15400 ,15476 ,15552 ,15628 ,15705 ,15782 ,15859 ,15936 ,16014 ,
    16092 ,16170 ,16248 ,16327 ,16405 ,16485 ,16564 ,16643 ,16723 ,16803 ,16883 ,16964 ,17045 ,17126 ,17207 ,17289 ,17370 ,17452 ,17535 ,17617 ,17700 ,17783 ,17866 ,17950 ,
    18033 ,18117 ,18202 ,18286 ,18371 ,18456 ,18541 ,18627 ,18712 ,18798 ,18885 ,18971 ,19058 ,19145 ,19232 ,19320 ,19408 ,19496 ,19584 ,19673 ,19761 ,19850 ,19940 ,20029 ,
    20119 ,20209 ,20300 ,20390 ,20481 ,20572 ,20664 ,20756 ,20848 ,20940 ,21032 ,21125 ,21218 ,21311 ,21405 ,21498 ,21592 ,21687 ,21781 ,21876 ,21971 ,22067 ,22162 ,22258 ,
    22354 ,22451 ,22547 ,22644 ,22742 ,22839 ,22937 ,23035 ,23133 ,23232 ,23331 ,23430 ,23529 ,23629 ,23729 ,23829 ,23929 ,24030 ,24131 ,24232 ,24334 ,24436 ,24538 ,24640 ,
    24743 ,24846 ,24949 ,25053 ,25156 ,25260 ,25365 ,25469 ,25574 ,25679 ,25785 ,25890 ,25996 ,26103 ,26209 ,26316 ,26423 ,26530 ,26638 ,26746 ,26854 ,26963 ,27071 ,27180 ,
    27290 ,27399 ,27509 ,27619 ,27730 ,27841 ,27952 ,28063 ,28175 ,28286 ,28399 ,28511 ,28624 ,28737 ,28850 ,28964 ,29078 ,29192 ,29306 ,29421 ,29536 ,29651 ,29767 ,29883 ,
    29999 ,30116 ,30232 ,30349 ,30467 ,30584 ,30702 ,30821 ,30939 ,31058 ,31177 ,31296 ,31416 ,31536 ,31656 ,31777 ,31898 ,32019 ,32141 ,32262 ,32384 ,32507 ,32629 ,32752 ,
    32876 ,32999 ,33123 ,33247 ,33372 ,33496 ,33621 ,33747 ,33872 ,33998 ,34124 ,34251 ,34378 ,34505 ,34632 ,34760 ,34888 ,35017 ,35145 ,35274 ,35403 ,35533 ,35663 ,35793 ,
    35923 ,36054 ,36185 ,36317 ,36448 ,36580 ,36713 ,36845 ,36978 ,37112 ,37245 ,37379 ,37513 ,37648 ,37782 ,37917 ,38053 ,38189 ,38325 ,38461 ,38598 ,38735 ,38872 ,39009 ,
    39147 ,39286 ,39424 ,39563 ,39702 ,39841 ,39981 ,40121 ,40262 ,40402 ,40544 ,40685 ,40827 ,40969 ,41111 ,41253 ,41396 ,41540 ,41683 ,41827 ,41971 ,42116 ,42261 ,42406 ,
    42551 ,42697 ,42843 ,42990 ,43137 ,43284 ,43431 ,43579 ,43727 ,43875 ,44024 ,44173 ,44322 ,44472 ,44622 ,44772 ,44923 ,45074 ,45225 ,45377 ,45529 ,45681 ,45834 ,45987 ,
    46140 ,46294 ,46448 ,46602 ,46756 ,46911 ,47067 ,47222 ,47378 ,47534 ,47691 ,47848 ,48005 ,48163 ,48320 ,48479 ,48637 ,48796 ,48955 ,49115 ,49275 ,49435 ,49596 ,49756 ,
    49918 ,50079 ,50241 ,50403 ,50566 ,50729 ,50892 ,51056 ,51220 ,51384 ,51548 ,51713 ,51879 ,52044 ,52210 ,52377 ,52543 ,52710 ,52877 ,53045 ,53213 ,53381 ,53550 ,53719 ,
    53889 ,54058 ,54228 ,54399 ,54569 ,54741 ,54912 ,55084 ,55256 ,55428 ,55601 ,55774 ,55948 ,56122 ,56296 ,56470 ,56645 ,56820 ,56996 ,57172 ,57348 ,57525 ,57702 ,57879 ,
    58057 ,58235 ,58413 ,58592 ,58771 ,58951 ,59130 ,59310 ,59491 ,59672 ,59853 ,60035 ,60216 ,60399 ,60581 ,60764 ,60948 ,61131 ,61315 ,61500 ,61684 ,61870 ,62055 ,62241 ,
    62427 ,62614 ,62800 ,62988 ,63175 ,63363 ,63552 ,63740 ,63929 ,64119 ,64308 ,64499 ,64689 ,64880 ,65071 ,65263 ,65455 ,65647 ,65839 ,66033 ,66226 ,66420 ,66614 ,66808 ,
    67003 ,67198 ,67394 ,67590 ,67786 ,67983 ,68180 ,68377 ,68575 ,68773 ,68972 ,69170 ,69370 ,69569 ,69769 ,69970 ,70170 ,70371 ,70573 ,70775 ,70977 ,71179 ,71382 ,71586 ,
    71789 ,71993 ,72198 ,72403 ,72608 ,72813 ,73019 ,73225 ,73432 ,73639 ,73847 ,74054 ,74263 ,74471 ,74680 ,74889 ,75099 ,75309 ,75519 ,75730 ,75941 ,76153 ,76365 ,76577 ,
    76790 ,77003 ,77216 ,77430 ,77645 ,77859 ,78074 ,78289 ,78505 ,78721 ,78938 ,79155 ,79372 ,79590 ,79808 ,80026 ,80245 ,80464 ,80684 ,80904 ,81124 ,81345 ,81566 ,81787 ,
    82009 ,82231 ,82454 ,82677 ,82900 ,83124 ,83348 ,83573 ,83798 ,84023 ,84249 ,84475 ,84702 ,84929 ,85156 ,85384 ,85612 ,85840 ,86069 ,86299 ,86528 ,86758 ,86989 ,87220 ,
    87451 ,87683 ,87915 ,88147 ,88380 ,88613 ,88847 ,89081 ,89315 ,89550 ,89785 ,90021 ,90257 ,90493 ,90730 ,90967 ,91205 ,91443 ,91681 ,91920 ,92159 ,92398 ,92638 ,92879 ,
    93120 ,93361 ,93602 ,93844 ,94087 ,94329 ,94573 ,94816 ,95060 ,95305 ,95549 ,95795 ,96040 ,96286 ,96533 ,96779 ,97027 ,97274 ,97522 ,97771 ,98020 ,98269 ,98519 ,98769 ,
    99019 ,99270 ,99521 ,99773 ,100025 ,100278 ,100530 ,100784 ,101038 ,101292 ,101546 ,101801 ,102057 ,102312 ,102569 ,102825 ,103082 ,103340 ,103598 ,103856 ,104115 ,104374 ,104633 ,104893 ,105154 ,
    105414 ,105676 ,105937 ,106199 ,106462 ,106724 ,106988 ,107251 ,107515 ,107780 ,108045 ,108310 ,108576 ,108842 ,109109 ,109376 ,109643 ,109911 ,110179 ,110448 ,110717 ,110987 ,111257 ,111527 ,111798 ,
    112069 ,112341 ,112613 ,112885 ,113158 ,113432 ,113706 ,113980 ,114254 ,114529 ,114805 ,115081 ,115357 ,115634 ,115911 ,116189 ,116467 ,116745 ,117024 ,117303 ,117583 ,117863 ,118144 ,118425 ,118706 ,
    118988 ,119271 ,119553 ,119837 ,120120 ,120404 ,120689 ,120974 ,121259 ,121545 ,121831 ,122118 ,122405 ,122692 ,122980 ,123268 ,123557 ,123846 ,124136 ,124426 ,124717 ,125008 ,125299 ,125591 ,125883 ,
    126176 ,126469 ,126763 ,127057 ,127351 ,127646 ,127942 ,128237 ,128534 ,128830 ,129127 ,129425 ,129723 ,130021 ,130320 ,130620 ,130919 ,131220 ,131520 ,131821 ,132123 ,132425 ,132727 ,133030 ,133333
};
//筒灯定频调光600Hz
const uint32_t cdn_pwm_freq[DIM_MAX_VALUE_INDEX] =
{
    0 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,
    133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332 ,133332
};
//筒灯线性调色
const uint32_t cdn_pwm_ct_duty[DIM_MAX_VALUE_INDEX] =
{
    0,
    25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500,525,550,575,600,625,
    650,675,700,725,750,775,800,825,850,875,900,925,950,975,1000,1025,1050,1075,1100,1125,1150,1175,1200,1225,1250,
    1275,1300,1325,1350,1375,1400,1425,1450,1475,1500,1525,1550,1575,1600,1625,1650,1675,1700,1725,1750,1775,1800,1825,1850,1875,
    1900,1925,1950,1975,2000,2025,2050,2075,2100,2125,2150,2175,2200,2225,2250,2275,2300,2325,2350,2375,2400,2425,2450,2475,2500,
    2525,2550,2575,2600,2625,2650,2675,2700,2725,2750,2775,2800,2825,2850,2875,2900,2925,2950,2975,3000,3025,3050,3075,3100,3125,
    3150,3175,3200,3225,3250,3275,3300,3325,3350,3375,3400,3425,3450,3475,3500,3525,3550,3575,3600,3625,3650,3675,3700,3725,3750,
    3775,3800,3825,3850,3875,3900,3925,3950,3975,4000,4025,4050,4075,4100,4125,4150,4175,4200,4225,4250,4275,4300,4325,4350,4375,
    4400,4425,4450,4475,4500,4525,4550,4575,4600,4625,4650,4675,4700,4725,4750,4775,4800,4825,4850,4875,4900,4925,4950,4975,5000,
    5025,5050,5075,5100,5125,5150,5175,5200,5225,5250,5275,5300,5325,5350,5375,5400,5425,5450,5475,5500,5525,5550,5575,5600,5625,
    5650,5675,5700,5725,5750,5775,5800,5825,5850,5875,5900,5925,5950,5975,6000,6025,6050,6075,6100,6125,6150,6175,6200,6225,6250,
    6275,6300,6325,6350,6375,6400,6425,6450,6475,6500,6525,6550,6575,6600,6625,6650,6675,6700,6725,6750,6775,6800,6825,6850,6875,
    6900,6925,6950,6975,7000,7025,7050,7075,7100,7125,7150,7175,7200,7225,7250,7275,7300,7325,7350,7375,7400,7425,7450,7475,7500,
    7525,7550,7575,7600,7625,7650,7675,7700,7725,7750,7775,7800,7825,7850,7875,7900,7925,7950,7975,8000,8025,8050,8075,8100,8125,
    8150,8175,8200,8225,8250,8275,8300,8325,8350,8375,8400,8425,8450,8475,8500,8525,8550,8575,8600,8625,8650,8675,8700,8725,8750,
    8775,8800,8825,8850,8875,8900,8925,8950,8975,9000,9025,9050,9075,9100,9125,9150,9175,9200,9225,9250,9275,9300,9325,9350,9375,
    9400,9425,9450,9475,9500,9525,9550,9575,9600,9625,9650,9675,9700,9725,9750,9775,9800,9825,9850,9875,9900,9925,9950,9975,10000,
    10025,10050,10075,10100,10125,10150,10175,10200,10225,10250,10275,10300,10325,10350,10375,10400,10425,10450,10475,10500,10525,
    10550,10575,10600,10625,10650,10675,10700,10725,10750,10775,10800,10825,10850,10875,10900,10925,10950,10975,11000,11025,11050,
    11075,11100,11125,11150,11175,11200,11225,11250,11275,11300,11325,11350,11375,11400,11425,11450,11475,11500,11525,11550,11575,
    11600,11625,11650,11675,11700,11725,11750,11775,11800,11825,11850,11875,11900,11925,11950,11975,12000,12025,12050,12075,12100,
    12125,12150,12175,12200,12225,12250,12275,12300,12325,12350,12375,12400,12425,12450,12475,12500,12525,12550,12575,12600,12625,
    12650,12675,12700,12725,12750,12775,12800,12825,12850,12875,12900,12925,12950,12975,13000,13025,13050,13075,13100,13125,13150,
    13175,13200,13225,13250,13275,13300,13325,13350,13375,13400,13425,13450,13475,13500,13525,13550,13575,13600,13625,13650,13675,
    13700,13725,13750,13775,13800,13825,13850,13875,13900,13925,13950,13975,14000,14025,14050,14075,14100,14125,14150,14175,14200,
    14225,14250,14275,14300,14325,14350,14375,14400,14425,14450,14475,14500,14525,14550,14575,14600,14625,14650,14675,14700,14725,
    14750,14775,14800,14825,14850,14875,14900,14925,14950,14975,15000,15025,15050,15075,15100,15125,15150,15175,15200,15225,15250,
    15275,15300,15325,15350,15375,15400,15425,15450,15475,15500,15525,15550,15575,15600,15625,15650,15675,15700,15725,15750,15775,
    15800,15825,15850,15875,15900,15925,15950,15975,16000,16025,16050,16075,16100,16125,16150,16175,16200,16225,16250,16275,16300,
    16325,16350,16375,16400,16425,16450,16475,16500,16525,16550,16575,16600,16625,16650,16675,16700,16725,16750,16775,16800,16825,
    16850,16875,16900,16925,16950,16975,17000,17025,17050,17075,17100,17125,17150,17175,17200,17225,17250,17275,17300,17325,17350,
    17375,17400,17425,17450,17475,17500,17525,17550,17575,17600,17625,17650,17675,17700,17725,17750,17775,17800,17825,17850,17875,
    17900,17925,17950,17975,18000,18025,18050,18075,18100,18125,18150,18175,18200,18225,18250,18275,18300,18325,18350,18375,18400,
    18425,18450,18475,18500,18525,18550,18575,18600,18625,18650,18675,18700,18725,18750,18775,18800,18825,18850,18875,18900,18925,
    18950,18975,19000,19025,19050,19075,19100,19125,19150,19175,19200,19225,19250,19275,19300,19325,19350,19375,19400,19425,19450,
    19475,19500,19525,19550,19575,19600,19625,19650,19675,19700,19725,19750,19775,19800,19825,19850,19875,19900,19925,19950,19975,
    20000,20025,20050,20075,20100,20125,20150,20175,20200,20225,20250,20275,20300,20325,20350,20375,20400,20425,20450,20475,20500,
    20525,20550,20575,20600,20625,20650,20675,20700,20725,20750,20775,20800,20825,20850,20875,20900,20925,20950,20975,21000,21025,
    21050,21075,21100,21125,21150,21175,21200,21225,21250,21275,21300,21325,21350,21375,21400,21425,21450,21475,21500,21525,21550,
    21575,21600,21625,21650,21675,21700,21725,21750,21775,21800,21825,21850,21875,21900,21925,21950,21975,22000,22025,22050,22075,
    22100,22125,22150,22175,22200,22225,22250,22275,22300,22325,22350,22375,22400,22425,22450,22475,22500,22525,22550,22575,22600,
    22625,22650,22675,22700,22725,22750,22775,22800,22825,22850,22875,22900,22925,22950,22975,23000,23025,23050,23075,23100,23125,
    23150,23175,23200,23225,23250,23275,23300,23325,23350,23375,23400,23425,23450,23475,23500,23525,23550,23575,23600,23625,23650,
    23675,23700,23725,23750,23775,23800,23825,23850,23875,23900,23925,23950,23975,24000,24025,24050,24075,24100,24125,24150,24175,
    24200,24225,24250,24275,24300,24325,24350,24375,24400,24425,24450,24475,24500,24525,24550,24575,24600,24625,24650,24675,24700,
    24725,24750,24775,24800,24825,24850,24875,24900,24925,24950,24975,25000
};
#else
#if 1
//筒灯曲线调光
const uint32_t cdn_pwm_duty[DIM_MAX_VALUE_INDEX] =
{
    0,
    1851,1828,1806,1785,1766,1747,1729,1713,1697,1682,1667,1654,1641,1628,1617,1605,1595,1585,1575,1566,1557,1549,1541,1533,1526,1519,1512,1506,1500,1494,1489,1484,1479,1474,1470,1465,
    1461,1458,1454,1451,1447,1444,1441,1439,1436,1434,1432,1429,1427,1426,1424,1422,1421,1420,1418,1417,1416,1415,1415,1414,1413,1413,1412,1412,1412,1412,1412,1412,1412,1412,1412,1413,
    1413,1414,1414,1415,1415,1416,1417,1418,1419,1420,1421,1422,1423,1424,1425,1427,1428,1429,1431,1432,1434,1436,1437,1439,1441,1442,1444,1446,1448,1450,1452,1454,1456,1458,1460,1462,
    1464,1467,1469,1471,1473,1476,1478,1481,1483,1485,1488,1491,1493,1496,1498,1501,1504,1506,1509,1512,1515,1517,1520,1523,1526,1529,1532,1535,1538,1541,1544,1547,1550,1553,1556,1559,
    1562,1566,1569,1572,1575,1579,1582,1585,1589,1592,1595,1599,1602,1605,1609,1612,1616,1619,1623,1626,1630,1634,1637,1641,1644,1648,1652,1655,1659,1663,1666,1670,1674,1678,1682,1685,
    1689,1693,1697,1701,1705,1709,1712,1716,1720,1724,1728,1732,1736,1740,1744,1748,1752,1756,1761,1765,1769,1773,1777,1781,1785,1790,1794,1798,1802,1806,1811,1815,1819,1823,1828,1832,
    1836,1841,1845,1849,1854,1858,1863,1867,1871,1876,1880,1885,1889,1894,1898,1903,1907,1912,1916,1921,1925,1930,1935,1939,1944,1948,1953,1958,1962,1967,1972,1976,1981,1986,1990,1995,
    2000,2005,2009,2014,2019,2024,2029,2033,2038,2043,2048,2053,2058,2062,2067,2072,2077,2082,2087,2092,2097,2102,2107,2112,2117,2122,2127,2132,2137,2142,2147,2152,2157,2162,2167,2172,
    2177,2182,2188,2193,2198,2203,2208,2213,2219,2224,2229,2234,2239,2245,2250,2255,2260,2266,2271,2276,2281,2287,2292,2297,2303,2308,2313,2319,2324,2329,2335,2340,2346,2351,2356,2362,
    2367,2373,2378,2384,2389,2395,2400,2406,2411,2417,2422,2428,2433,2439,2444,2450,2455,2461,2467,2472,2478,2483,2489,2495,2500,2506,2512,2517,2523,2529,2534,2540,2546,2552,2557,2563,
    2569,2581,2593,2605,2618,2630,2642,2655,2667,2680,2692,2705,2717,2730,2743,2755,2768,2781,2794,2807,2820,2833,2846,2859,2872,2885,2898,2911,2924,2937,2951,2964,2977,2991,3004,3018,
    3031,3045,3058,3072,3086,3099,3113,3127,3141,3155,3169,3183,3197,3211,3225,3239,3253,3267,3281,3296,3310,3324,3339,3353,3367,3382,3396,3411,3426,3440,3455,3470,3485,3499,3514,3529,
    3544,3559,3574,3589,3604,3619,3635,3650,3665,3681,3696,3711,3727,3742,3758,3773,3789,3805,3820,3836,3852,3868,3883,3899,3915,3931,3947,3963,3979,3995,4012,4028,4044,4061,4077,4093,
    4110,4126,4143,4159,4176,4193,4209,4226,4243,4260,4276,4293,4310,4327,4344,4361,4379,4396,4413,4430,4447,4465,4482,4500,4517,4535,4552,4570,4587,4605,4623,4641,4658,4676,4694,4712,
    4730,4748,4766,4784,4803,4821,4839,4857,4876,4894,4913,4931,4950,4968,4987,5005,5024,5043,5062,5081,5099,5118,5137,5156,5175,5195,5214,5233,5252,5272,5291,5310,5330,5349,5369,5388,
    5408,5428,5447,5467,5487,5507,5527,5546,5566,5586,5607,5627,5647,5667,5687,5708,5728,5748,5769,5789,5810,5830,5851,5872,5893,5913,5934,5955,5976,5997,6018,6039,6060,6081,6102,6124,
    6145,6166,6188,6209,6231,6252,6274,6295,6317,6339,6361,6382,6404,6426,6448,6470,6492,6514,6536,6559,6581,6603,6626,6648,6670,6693,6716,6738,6761,6783,6806,6829,6852,6875,6898,6921,
    6944,6967,6990,7013,7036,7060,7083,7106,7130,7153,7177,7200,7224,7248,7271,7295,7319,7343,7367,7391,7415,7439,7463,7487,7512,7536,7560,7585,7609,7633,7658,7683,7707,7732,7757,7781,
    7806,7831,7856,7881,7906,7931,7956,7982,8007,8032,8057,8083,8108,8134,8159,8185,8211,8236,8262,8288,8314,8340,8366,8392,8418,8444,8470,8496,8523,8549,8575,8602,8628,8655,8681,8708,
    8735,8762,8788,8815,8842,8869,8896,8923,8950,8978,9005,9032,9059,9087,9114,9142,9169,9197,9224,9252,9280,9308,9336,9364,9392,9420,9448,9476,9504,9532,9561,9589,9617,9646,9674,9703,
    9731,9760,9789,9818,9847,9875,9904,9933,9962,9992,10021,10050,10079,10109,10138,10167,10197,10226,10256,10286,10315,10345,10375,10405,10435,10465,10495,10525,10555,10585,10616,10646,
    10676,10707,10737,10768,10798,10829,10860,10891,10921,10952,10983,11014,11045,11076,11108,11139,11170,11201,11233,11264,11296,11327,11359,11391,11422,11454,11486,11518,11550,11582,
    11614,11646,11678,11711,11743,11775,11808,11840,11873,11905,11938,11971,12003,12036,12069,12102,12135,12168,12201,12234,12267,12301,12334,12367,12401,12434,12468,12502,12535,12569,
    12603,12637,12671,12705,12739,12773,12807,12841,12875,12910,12944,12979,13013,13048,13082,13117,13152,13187,13221,13256,13291,13326,13361,13397,13432,13467,13502,13538,13573,13609,
    13644,13680,13716,13751,13787,13823,13859,13895,13931,13967,14003,14040,14076,14112,14149,14185,14222,14258,14295,14332,14368,14405,14442,14479,14516,14553,14590,14628,14665,14702,
    14740,14777,14815,14852,14890,14927,14965,15003,15041,15079,15117,15155,15193,15231,15269,15308,15346,15385,15423,15462,15500,15539,15578,15616,15655,15694,15733,15772,15811,15851,
    15890,15929,15968,16008,16047,16087,16127,16166,16206,16246,16286,16326,16366,16406,16446,16486,16526,16566,16607,16647,16688,16728,16769,16810,16850,16891,16932,16973,17014,17055,
    17096,17137,17179,17220,17261,17303,17344,17386,17427,17469,17511,17553,17595,17637,17679,17721,17763,17805,17847,17890,17932,17975,18017,18060,18102,18145,18188,18231,18274,18317,
    18360,18403,18446,18489,18533,18576,18619,18663,18707,18750,18794,18838,18882,18925,18969,19013,19058,19102,19146,19190,19235,19279,19324,19368,19413,19457,19502,19547,19592,19637,
    20000,20000,20000,20000,20000,20000,20000,20000,
};

//筒灯变频调光
const uint32_t cdn_pwm_freq[DIM_MAX_VALUE_INDEX] =
{
    0,
    199999,195121,190475,186046,181817,177777,173912,170212,166666,163264,159999,156862,153845,150942,148147,145454,142856,140350,137930,135592,133332,131147,129031,126983,124999,123076,
    121211,119402,117646,115941,114285,112675,111110,109588,108107,106666,105262,103895,102563,101265,99999,98764,97560,96385,95237,94117,93022,91953,90908,89887,88888,87911,86956,86021,
    85105,84210,83332,82473,81632,80807,79999,79207,78430,77669,76922,76189,75471,74765,74073,73393,72726,72071,71428,70795,70174,69564,68965,68375,67796,67226,66666,66115,65573,65040,
    64515,63999,63491,62991,62499,62015,61537,61068,60605,60149,59700,59258,58823,58393,57970,57553,57142,56737,56337,55943,55555,55171,54794,54421,54053,53690,53332,52979,52631,52287,
    51947,51612,51281,50954,50632,50313,49999,49688,49382,49079,48779,48484,48192,47903,47618,47336,47058,46783,46511,46242,45976,45713,45454,45197,44943,44692,44443,44198,43955,43715,
    43477,43242,43010,42780,42552,42327,42104,41884,41666,41450,41236,41025,40815,40608,40403,40200,39999,39800,39603,39408,39215,39023,38834,38646,38461,38277,38094,37914,37735,37558,
    37382,37208,37036,36865,36696,36529,36363,36198,36035,35873,35713,35555,35397,35241,35087,34933,34782,34631,34482,34334,34187,34042,33897,33754,33612,33472,33332,33194,33057,32921,
    32786,32652,32519,32388,32257,32128,31999,31872,31745,31620,31495,31372,31249,31127,31007,30887,30768,30650,30533,30417,30302,30188,30074,29962,29850,29739,29629,29519,29411,29303,
    29196,29090,28985,28880,28776,28673,28570,28469,28368,28268,28168,28069,27971,27874,27777,27681,27585,27490,27396,27303,27210,27118,27026,26935,26845,26755,26666,26577,26489,26402,
    26315,26229,26143,26058,25973,25889,25805,25722,25640,25558,25477,25396,25315,25236,25156,25077,24999,24921,24844,24767,24690,24614,24539,24464,24389,24315,24241,24168,24095,24023,
    23951,23880,23809,23738,23668,23598,23528,23459,23391,23323,23255,23187,23120,23054,22988,22922,22856,22791,22726,22662,22598,22534,22471,22408,22345,22283,22221,22160,22098,22038,
    21977,21917,21857,21797,21738,21679,21621,21562,21504,21447,21389,21332,21276,21219,21163,21107,21052,20996,20941,20887,20832,20778,20724,20671,20618,20565,20512,20459,20407,20355,
    20304,20252,20201,20150,20100,20049,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
    19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,19999,
};
#endif

#if 0
//筒灯定频调光4k
const uint32_t cdn_pwm_freq[DIM_MAX_VALUE_INDEX] =
{
    0 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,
    19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999 ,19999
};

const uint32_t cdn_pwm_duty[DIM_MAX_VALUE_INDEX] =
{
    0 ,185 ,187 ,190 ,192 ,194 ,197 ,199 ,201 ,204 ,206 ,208 ,211 ,213 ,216 ,218 ,221 ,223 ,226 ,228 ,231 ,234 ,236 ,239 ,241 ,244 ,247 ,250 ,252 ,255 ,258 ,261 ,263 ,266 ,269 ,272 ,
    275 ,278 ,281 ,284 ,286 ,289 ,292 ,295 ,299 ,302 ,305 ,308 ,311 ,314 ,317 ,320 ,324 ,327 ,330 ,333 ,337 ,340 ,343 ,347 ,350 ,353 ,357 ,360 ,364 ,367 ,371 ,374 ,378 ,381 ,385 ,388 ,
    392 ,396 ,399 ,403 ,407 ,410 ,414 ,418 ,422 ,426 ,429 ,433 ,437 ,441 ,445 ,449 ,453 ,457 ,461 ,465 ,469 ,473 ,477 ,481 ,486 ,490 ,494 ,498 ,502 ,507 ,511 ,515 ,520 ,524 ,529 ,533 ,
    537 ,542 ,546 ,551 ,555 ,560 ,564 ,569 ,574 ,578 ,583 ,588 ,592 ,597 ,602 ,607 ,612 ,617 ,621 ,626 ,631 ,636 ,641 ,646 ,651 ,656 ,661 ,666 ,671 ,677 ,682 ,687 ,692 ,697 ,703 ,708 ,
    713 ,719 ,724 ,730 ,735 ,740 ,746 ,751 ,757 ,763 ,768 ,774 ,779 ,785 ,791 ,796 ,802 ,808 ,814 ,820 ,825 ,831 ,837 ,843 ,849 ,855 ,861 ,867 ,873 ,879 ,885 ,892 ,898 ,904 ,910 ,916 ,
    923 ,929 ,935 ,942 ,948 ,955 ,961 ,968 ,974 ,981 ,987 ,994 ,1000 ,1007 ,1014 ,1020 ,1027 ,1034 ,1041 ,1048 ,1054 ,1061 ,1068 ,1075 ,1082 ,1089 ,1096 ,1103 ,1110 ,1117 ,1125 ,1132 ,
    1139 ,1146 ,1153 ,1161 ,1168 ,1175 ,1183 ,1190 ,1198 ,1205 ,1213 ,1220 ,1228 ,1235 ,1243 ,1250 ,1258 ,1266 ,1274 ,1281 ,1289 ,1297 ,1305 ,1313 ,1321 ,1329 ,1337 ,1345 ,1353 ,1361 ,
    1369 ,1377 ,1385 ,1393 ,1402 ,1410 ,1418 ,1426 ,1435 ,1443 ,1452 ,1460 ,1468 ,1477 ,1486 ,1494 ,1503 ,1511 ,1520 ,1529 ,1537 ,1546 ,1555 ,1564 ,1573 ,1582 ,1591 ,1599 ,1608 ,1617 ,
    1627 ,1636 ,1645 ,1654 ,1663 ,1672 ,1682 ,1691 ,1700 ,1710 ,1719 ,1728 ,1738 ,1747 ,1757 ,1766 ,1776 ,1786 ,1795 ,1805 ,1815 ,1824 ,1834 ,1844 ,1854 ,1864 ,1874 ,1884 ,1894 ,1904 ,
    1914 ,1924 ,1934 ,1944 ,1954 ,1964 ,1975 ,1985 ,1995 ,2006 ,2016 ,2026 ,2037 ,2047 ,2058 ,2069 ,2079 ,2090 ,2100 ,2111 ,2122 ,2133 ,2143 ,2154 ,2165 ,2176 ,2187 ,2198 ,2209 ,2220 ,
    2231 ,2242 ,2254 ,2265 ,2276 ,2287 ,2299 ,2310 ,2321 ,2333 ,2344 ,2356 ,2367 ,2379 ,2390 ,2402 ,2414 ,2425 ,2437 ,2449 ,2461 ,2473 ,2485 ,2497 ,2508 ,2520 ,2533 ,2545 ,2557 ,2569 ,
    2581 ,2593 ,2606 ,2618 ,2630 ,2643 ,2655 ,2667 ,2680 ,2692 ,2705 ,2718 ,2730 ,2743 ,2756 ,2768 ,2781 ,2794 ,2807 ,2820 ,2833 ,2846 ,2859 ,2872 ,2885 ,2898 ,2911 ,2924 ,2938 ,2951 ,
    2964 ,2978 ,2991 ,3004 ,3018 ,3031 ,3045 ,3059 ,3072 ,3086 ,3100 ,3113 ,3127 ,3141 ,3155 ,3169 ,3183 ,3197 ,3211 ,3225 ,3239 ,3253 ,3267 ,3281 ,3296 ,3310 ,3324 ,3339 ,3353 ,3368 ,
    3382 ,3397 ,3411 ,3426 ,3441 ,3455 ,3470 ,3485 ,3500 ,3514 ,3529 ,3544 ,3559 ,3574 ,3589 ,3605 ,3620 ,3635 ,3650 ,3665 ,3681 ,3696 ,3711 ,3727 ,3742 ,3758 ,3773 ,3789 ,3805 ,3820 ,
    3836 ,3852 ,3868 ,3884 ,3899 ,3915 ,3931 ,3947 ,3963 ,3980 ,3996 ,4012 ,4028 ,4044 ,4061 ,4077 ,4093 ,4110 ,4126 ,4143 ,4159 ,4176 ,4193 ,4209 ,4226 ,4243 ,4260 ,4277 ,4294 ,4311 ,
    4328 ,4345 ,4362 ,4379 ,4396 ,4413 ,4430 ,4448 ,4465 ,4482 ,4500 ,4517 ,4535 ,4552 ,4570 ,4588 ,4605 ,4623 ,4641 ,4659 ,4677 ,4694 ,4712 ,4730 ,4748 ,4767 ,4785 ,4803 ,4821 ,4839 ,
    4858 ,4876 ,4894 ,4913 ,4931 ,4950 ,4968 ,4987 ,5006 ,5024 ,5043 ,5062 ,5081 ,5100 ,5119 ,5138 ,5157 ,5176 ,5195 ,5214 ,5233 ,5252 ,5272 ,5291 ,5311 ,5330 ,5349 ,5369 ,5389 ,5408 ,
    5428 ,5448 ,5467 ,5487 ,5507 ,5527 ,5547 ,5567 ,5587 ,5607 ,5627 ,5647 ,5667 ,5688 ,5708 ,5728 ,5749 ,5769 ,5790 ,5810 ,5831 ,5851 ,5872 ,5893 ,5914 ,5934 ,5955 ,5976 ,5997 ,6018 ,
    6039 ,6060 ,6082 ,6103 ,6124 ,6145 ,6167 ,6188 ,6209 ,6231 ,6252 ,6274 ,6296 ,6317 ,6339 ,6361 ,6383 ,6405 ,6426 ,6448 ,6470 ,6493 ,6515 ,6537 ,6559 ,6581 ,6604 ,6626 ,6648 ,6671 ,
    6693 ,6716 ,6738 ,6761 ,6784 ,6807 ,6829 ,6852 ,6875 ,6898 ,6921 ,6944 ,6967 ,6990 ,7013 ,7037 ,7060 ,7083 ,7107 ,7130 ,7154 ,7177 ,7201 ,7224 ,7248 ,7272 ,7296 ,7319 ,7343 ,7367 ,
    7391 ,7415 ,7439 ,7463 ,7488 ,7512 ,7536 ,7561 ,7585 ,7609 ,7634 ,7658 ,7683 ,7708 ,7732 ,7757 ,7782 ,7807 ,7832 ,7856 ,7881 ,7907 ,7932 ,7957 ,7982 ,8007 ,8033 ,8058 ,8083 ,8109 ,
    8134 ,8160 ,8185 ,8211 ,8237 ,8263 ,8288 ,8314 ,8340 ,8366 ,8392 ,8418 ,8444 ,8471 ,8497 ,8523 ,8549 ,8576 ,8602 ,8629 ,8655 ,8682 ,8709 ,8735 ,8762 ,8789 ,8816 ,8843 ,8870 ,8897 ,
    8924 ,8951 ,8978 ,9005 ,9032 ,9060 ,9087 ,9115 ,9142 ,9170 ,9197 ,9225 ,9253 ,9280 ,9308 ,9336 ,9364 ,9392 ,9420 ,9448 ,9476 ,9504 ,9533 ,9561 ,9589 ,9618 ,9646 ,9675 ,9703 ,9732 ,
    9761 ,9789 ,9818 ,9847 ,9876 ,9905 ,9934 ,9963 ,9992 ,10021 ,10050 ,10080 ,10109 ,10138 ,10168 ,10197 ,10227 ,10257 ,10286 ,10316 ,10346 ,10376 ,10405 ,10435 ,10465 ,10495 ,10526 ,
    10556 ,10586 ,10616 ,10647 ,10677 ,10707 ,10738 ,10768 ,10799 ,10830 ,10860 ,10891 ,10922 ,10953 ,10984 ,11015 ,11046 ,11077 ,11108 ,11139 ,11171 ,11202 ,11233 ,11265 ,11296 ,11328 ,
    11360 ,11391 ,11423 ,11455 ,11487 ,11518 ,11550 ,11582 ,11615 ,11647 ,11679 ,11711 ,11743 ,11776 ,11808 ,11841 ,11873 ,11906 ,11938 ,11971 ,12004 ,12037 ,12070 ,12103 ,12136 ,12169 ,
    12202 ,12235 ,12268 ,12301 ,12335 ,12368 ,12402 ,12435 ,12469 ,12502 ,12536 ,12570 ,12604 ,12637 ,12671 ,12705 ,12739 ,12773 ,12808 ,12842 ,12876 ,12910 ,12945 ,12979 ,13014 ,13048 ,
    13083 ,13118 ,13152 ,13187 ,13222 ,13257 ,13292 ,13327 ,13362 ,13397 ,13432 ,13468 ,13503 ,13538 ,13574 ,13609 ,13645 ,13681 ,13716 ,13752 ,13788 ,13824 ,13860 ,13896 ,13932 ,13968 ,
    14004 ,14040 ,14077 ,14113 ,14149 ,14186 ,14222 ,14259 ,14296 ,14332 ,14369 ,14406 ,14443 ,14480 ,14517 ,14554 ,14591 ,14628 ,14666 ,14703 ,14740 ,14778 ,14815 ,14853 ,14890 ,14928 ,
    14966 ,15004 ,15042 ,15080 ,15118 ,15156 ,15194 ,15232 ,15270 ,15309 ,15347 ,15385 ,15424 ,15462 ,15501 ,15540 ,15578 ,15617 ,15656 ,15695 ,15734 ,15773 ,15812 ,15851 ,15891 ,15930 ,
    15969 ,16009 ,16048 ,16088 ,16127 ,16167 ,16207 ,16247 ,16286 ,16326 ,16366 ,16406 ,16446 ,16487 ,16527 ,16567 ,16608 ,16648 ,16689 ,16729 ,16770 ,16810 ,16851 ,16892 ,16933 ,16974 ,
    17015 ,17056 ,17097 ,17138 ,17179 ,17221 ,17262 ,17304 ,17345 ,17387 ,17428 ,17470 ,17512 ,17554 ,17596 ,17637 ,17679 ,17722 ,17764 ,17806 ,17848 ,17891 ,17933 ,17975 ,18018 ,18061 ,
    18103 ,18146 ,18189 ,18232 ,18275 ,18318 ,18361 ,18404 ,18447 ,18490 ,18534 ,18577 ,18620 ,18664 ,18708 ,18751 ,18795 ,18839 ,18882 ,18926 ,18970 ,19014 ,19059 ,19103 ,19147 ,19191 ,
    19236 ,19280 ,19325 ,19369 ,19414 ,19458 ,19503 ,19548 ,19593 ,19638 ,19683 ,19728 ,19773 ,19818 ,19864 ,19909 ,19955 ,20000
};

#endif

//筒灯线性调色
const uint32_t cdn_pwm_ct_duty[DIM_MAX_VALUE_INDEX] =
{
		0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 
		100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 
		200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 
		300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380, 385, 390, 395, 
		400, 405, 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 460, 465, 470, 475, 480, 485, 490, 495, 
		500, 505, 510, 515, 520, 525, 530, 535, 540, 545, 550, 555, 560, 565, 570, 575, 580, 585, 590, 595, 
		600, 605, 610, 615, 620, 625, 630, 635, 640, 645, 650, 655, 660, 665, 670, 675, 680, 685, 690, 695, 
		700, 705, 710, 715, 720, 725, 730, 735, 740, 745, 750, 755, 760, 765, 770, 775, 780, 785, 790, 795, 
		800, 805, 810, 815, 820, 825, 830, 835, 840, 845, 850, 855, 860, 865, 870, 875, 880, 885, 890, 895, 
		900, 905, 910, 915, 920, 925, 930, 935, 940, 945, 950, 955, 960, 965, 970, 975, 980, 985, 990, 995, 
		1000, 1005, 1010, 1015, 1020, 1025, 1030, 1035, 1040, 1045, 1050, 1055, 1060, 1065, 1070, 1075, 1080, 1085, 1090, 1095, 
		1010, 1105, 1110, 1115, 1120, 1125, 1130, 1135, 1140, 1145, 1150, 1155, 1160, 1165, 1170, 1175, 1180, 1185, 1190, 1195, 
		1200, 1205, 1210, 1215, 1220, 1225, 1230, 1235, 1240, 1245, 1250, 1255, 1260, 1265, 1270, 1275, 1280, 1285, 1290, 1295, 
		1300, 1305, 1310, 1315, 1320, 1325, 1330, 1335, 1340, 1345, 1350, 1355, 1360, 1365, 1370, 1375, 1380, 1385, 1390, 1395, 
		1400, 1405, 1410, 1415, 1420, 1425, 1430, 1435, 1440, 1445, 1450, 1455, 1460, 1465, 1470, 1475, 1480, 1485, 1490, 1495, 
		1500, 1505, 1510, 1515, 1520, 1525, 1530, 1535, 1540, 1545, 1550, 1555, 1560, 1565, 1570, 1575, 1580, 1585, 1590, 1595, 
		1600, 1605, 1610, 1615, 1620, 1625, 1630, 1635, 1640, 1645, 1650, 1655, 1660, 1665, 1670, 1675, 1680, 1685, 1690, 1695, 
		1700, 1705, 1710, 1715, 1720, 1725, 1730, 1735, 1740, 1745, 1750, 1755, 1760, 1765, 1770, 1775, 1780, 1785, 1790, 1795, 
		1800, 1805, 1810, 1815, 1820, 1825, 1830, 1835, 1840, 1845, 1850, 1855, 1860, 1865, 1870, 1875, 1880, 1885, 1890, 1895, 
		1900, 1905, 1910, 1915, 1920, 1925, 1930, 1935, 1940, 1945, 1950, 1955, 1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 
		2000, 2005, 2010, 2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050, 2055, 2060, 2065, 2070, 2075, 2080, 2085, 2090, 2095, 
		2010, 2105, 2110, 2115, 2120, 2125, 2130, 2135, 2140, 2145, 2150, 2155, 2160, 2165, 2170, 2175, 2180, 2185, 2190, 2195, 
		2200, 2205, 2210, 2215, 2220, 2225, 2230, 2235, 2240, 2245, 2250, 2255, 2260, 2265, 2270, 2275, 2280, 2285, 2290, 2295, 
		2300, 2305, 2310, 2315, 2320, 2325, 2330, 2335, 2340, 2345, 2350, 2355, 2360, 2365, 2370, 2375, 2380, 2385, 2390, 2395, 
		2400, 2405, 2410, 2415, 2420, 2425, 2430, 2435, 2440, 2445, 2450, 2455, 2460, 2465, 2470, 2475, 2480, 2485, 2490, 2495, 
		2500, 2505, 2510, 2515, 2520, 2525, 2530, 2535, 2540, 2545, 2550, 2555, 2560, 2565, 2570, 2575, 2580, 2585, 2590, 2595, 
		2600, 2605, 2610, 2615, 2620, 2625, 2630, 2635, 2640, 2645, 2650, 2655, 2660, 2665, 2670, 2675, 2680, 2685, 2690, 2695, 
		2700, 2705, 2710, 2715, 2720, 2725, 2730, 2735, 2740, 2745, 2750, 2755, 2760, 2765, 2770, 2775, 2780, 2785, 2790, 2795, 
		2800, 2805, 2810, 2815, 2820, 2825, 2830, 2835, 2840, 2845, 2850, 2855, 2860, 2865, 2870, 2875, 2880, 2885, 2890, 2895, 
		2900, 2905, 2910, 2915, 2920, 2925, 2930, 2935, 2940, 2945, 2950, 2955, 2960, 2965, 2970, 2975, 2980, 2985, 2990, 2995, 
		3000, 3005, 3010, 3015, 3020, 3025, 3030, 3035, 3040, 3045, 3050, 3055, 3060, 3065, 3070, 3075, 3080, 3085, 3090, 3095, 
		3100, 3105, 3110, 3115, 3120, 3125, 3130, 3135, 3140, 3145, 3150, 3155, 3160, 3165, 3170, 3175, 3180, 3185, 3190, 3195, 
		3200, 3205, 3210, 3215, 3220, 3225, 3230, 3235, 3240, 3245, 3250, 3255, 3260, 3265, 3270, 3275, 3280, 3285, 3290, 3295, 
		3300, 3305, 3310, 3315, 3320, 3325, 3330, 3335, 3340, 3345, 3350, 3355, 3360, 3365, 3370, 3375, 3380, 3385, 3390, 3395, 
		3400, 3405, 3410, 3415, 3420, 3425, 3430, 3435, 3440, 3445, 3450, 3455, 3460, 3465, 3470, 3475, 3480, 3485, 3490, 3495, 
		3500, 3505, 3510, 3515, 3520, 3525, 3530, 3535, 3540, 3545, 3550, 3555, 3560, 3565, 3570, 3575, 3580, 3585, 3590, 3595, 
		3600, 3605, 3610, 3615, 3620, 3625, 3630, 3635, 3640, 3645, 3650, 3655, 3660, 3665, 3670, 3675, 3680, 3685, 3690, 3695, 
		3700, 3705, 3710, 3715, 3720, 3725, 3730, 3735, 3740, 3745, 3750, 3755, 3760, 3765, 3770, 3775, 3780, 3785, 3790, 3795, 
		3800, 3805, 3810, 3815, 3820, 3825, 3830, 3835, 3840, 3845, 3850, 3855, 3860, 3865, 3870, 3875, 3880, 3885, 3890, 3895, 
		3900, 3905, 3910, 3915, 3920, 3925, 3930, 3935, 3940, 3945, 3950, 3955, 3960, 3965, 3970, 3975, 3980, 3985, 3990, 3995, 
		4000, 4005, 4010, 4015, 4020, 4025, 4030, 4035, 4040, 4045, 4050, 4055, 4060, 4065, 4070, 4075, 4080, 4085, 4090, 4095, 
		4100, 4105, 4110, 4115, 4120, 4125, 4130, 4135, 4140, 4145, 4150, 4155, 4160, 4165, 4170, 4175, 4180, 4185, 4190, 4195, 
		4200, 4205, 4210, 4215, 4220, 4225, 4230, 4235, 4240, 4245, 4250, 4255, 4260, 4265, 4270, 4275, 4280, 4285, 4290, 4295, 
		4300, 4305, 4310, 4315, 4320, 4325, 4330, 4335, 4340, 4345, 4350, 4355, 4360, 4365, 4370, 4375, 4380, 4385, 4390, 4395, 
		4400, 4405, 4410, 4415, 4420, 4425, 4430, 4435, 4440, 4445, 4450, 4455, 4460, 4465, 4470, 4475, 4480, 4485, 4490, 4495, 
		4500, 4505, 4510, 4515, 4520, 4525, 4530, 4535, 4540, 4545, 4550, 4555, 4560, 4565, 4570, 4575, 4580, 4585, 4590, 4595, 
		4600, 4605, 4610, 4615, 4620, 4625, 4630, 4635, 4640, 4645, 4650, 4655, 4660, 4665, 4670, 4675, 4680, 4685, 4690, 4695, 
		4700, 4705, 4710, 4715, 4720, 4725, 4730, 4735, 4740, 4745, 4750, 4755, 4760, 4765, 4770, 4775, 4780, 4785, 4790, 4795, 
		4800, 4805, 4810, 4815, 4820, 4825, 4830, 4835, 4840, 4845, 4850, 4855, 4860, 4865, 4870, 4875, 4880, 4885, 4890, 4895, 
		4900, 4905, 4910, 4915, 4920, 4925, 4930, 4935, 4940, 4945, 4950, 4955, 4960, 4965, 4970, 4975, 4980, 4985, 4990, 4995, 
		5000, 
};

#endif

sl_pwm_instance_t sl_pwm_lightness = {
  .timer = SL_PWM_PERIPHERAL_LT,
  .channel = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_CHANNEL),
  .port = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_PORT),
  .pin = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_PIN),
};

sl_pwm_instance_t sl_pwm_ct = {
  .timer = SL_PWM_PERIPHERAL_CT,
  .channel = (uint8_t)(SL_PWM_CT_OUTPUT_CHANNEL),
  .port = (uint8_t)(SL_PWM_CT_OUTPUT_PORT),
  .pin = (uint8_t)(SL_PWM_CT_OUTPUT_PIN),
};
#elif CDN_LIGHT_STRIP
//灯带曲线调光
const uint32_t cdn_pwm_duty[DIM_MAX_VALUE_INDEX] ={
	0, 185, 187, 190, 192, 194, 197, 199, 201, 204, 206, 208, 211, 213, 216, 218, 221, 
	223, 226, 228, 231, 234, 236, 239, 241, 244, 247, 250, 252, 255, 258, 261, 263, 266, 
	269, 272, 275, 278, 281, 284, 286, 289, 292, 295, 299, 302, 305, 308, 311, 314, 317, 
	320, 324, 327, 330, 333, 337, 340, 343, 347, 350, 353, 357, 360, 364, 367, 371, 374, 
	378, 381, 385, 388, 392, 396, 399, 403, 407, 410, 414, 418, 422, 426, 429, 433, 437, 
	441, 445, 449, 453, 457, 461, 465, 469, 473, 477, 481, 486, 490, 494, 498, 502, 507, 
	511, 515, 520, 524, 529, 533, 537, 542, 546, 551, 555, 560, 564, 569, 574, 578, 583, 
	588, 592, 597, 602, 607, 612, 617, 621, 626, 631, 636, 641, 646, 651, 656, 661, 666, 
	671, 677, 682, 687, 692, 697, 703, 708, 713, 719, 724, 730, 735, 740, 746, 751, 757, 
	763, 768, 774, 779, 785, 791, 796, 802, 808, 814, 820, 825, 831, 837, 843, 849, 855, 
	861, 867, 873, 879, 885, 892, 898, 904, 910, 916, 923, 929, 935, 942, 948, 955, 961, 
	968, 974, 981, 987, 994, 1000, 1007, 1014, 1020, 1027, 1034, 1041, 1048, 1054, 1061, 
	1068, 1075, 1082, 1089, 1096, 1103, 1110, 1117, 1125, 1132, 1139, 1146, 1153, 1161, 
	1168, 1175, 1183, 1190, 1198, 1205, 1213, 1220, 1228, 1235, 1243, 1250, 1258, 1266, 
	1274, 1281, 1289, 1297, 1305, 1313, 1321, 1329, 1337, 1345, 1353, 1361, 1369, 1377, 
	1385, 1393, 1402, 1410, 1418, 1426, 1435, 1443, 1452, 1460, 1468, 1477, 1486, 1494, 
	1503, 1511, 1520, 1529, 1537, 1546, 1555, 1564, 1573, 1582, 1591, 1599, 1608, 1617, 
	1627, 1636, 1645, 1654, 1663, 1672, 1682, 1691, 1700, 1710, 1719, 1728, 1738, 1747, 
	1757, 1766, 1776, 1786, 1795, 1805, 1815, 1824, 1834, 1844, 1854, 1864, 1874, 1884, 
	1894, 1904, 1914, 1924, 1934, 1944, 1954, 1964, 1975, 1985, 1995, 2006, 2016, 2026, 
	2037, 2047, 2058, 2069, 2079, 2090, 2100, 2111, 2122, 2133, 2143, 2154, 2165, 2176, 
	2187, 2198, 2209, 2220, 2231, 2242, 2254, 2265, 2276, 2287, 2299, 2310, 2321, 2333, 
	2344, 2356, 2367, 2379, 2390, 2402, 2414, 2425, 2437, 2449, 2461, 2473, 2485, 2497, 
	2508, 2520, 2533, 2545, 2557, 2569, 2581, 2593, 2606, 2618, 2630, 2643, 2655, 2667, 
	2680, 2692, 2705, 2718, 2730, 2743, 2756, 2768, 2781, 2794, 2807, 2820, 2833, 2846, 
	2859, 2872, 2885, 2898, 2911, 2924, 2938, 2951, 2964, 2978, 2991, 3004, 3018, 3031, 
	3045, 3059, 3072, 3086, 3100, 3113, 3127, 3141, 3155, 3169, 3183, 3197, 3211, 3225, 
	3239, 3253, 3267, 3281, 3296, 3310, 3324, 3339, 3353, 3368, 3382, 3397, 3411, 3426, 
	3441, 3455, 3470, 3485, 3500, 3514, 3529, 3544, 3559, 3574, 3589, 3605, 3620, 3635, 
	3650, 3665, 3681, 3696, 3711, 3727, 3742, 3758, 3773, 3789, 3805, 3820, 3836, 3852, 
	3868, 3884, 3899, 3915, 3931, 3947, 3963, 3980, 3996, 4012, 4028, 4044, 4061, 4077, 
	4093, 4110, 4126, 4143, 4159, 4176, 4193, 4209, 4226, 4243, 4260, 4277, 4294, 4311, 
	4328, 4345, 4362, 4379, 4396, 4413, 4430, 4448, 4465, 4482, 4500, 4517, 4535, 4552, 
	4570, 4588, 4605, 4623, 4641, 4659, 4677, 4694, 4712, 4730, 4748, 4767, 4785, 4803, 
	4821, 4839, 4858, 4876, 4894, 4913, 4931, 4950, 4968, 4987, 5006, 5024, 5043, 5062, 
	5081, 5100, 5119, 5138, 5157, 5176, 5195, 5214, 5233, 5252, 5272, 5291, 5311, 5330, 
	5349, 5369, 5389, 5408, 5428, 5448, 5467, 5487, 5507, 5527, 5547, 5567, 5587, 5607, 
	5627, 5647, 5667, 5688, 5708, 5728, 5749, 5769, 5790, 5810, 5831, 5851, 5872, 5893, 
	5914, 5934, 5955, 5976, 5997, 6018, 6039, 6060, 6082, 6103, 6124, 6145, 6167, 6188, 
	6209, 6231, 6252, 6274, 6296, 6317, 6339, 6361, 6383, 6405, 6426, 6448, 6470, 6493, 
	6515, 6537, 6559, 6581, 6604, 6626, 6648, 6671, 6693, 6716, 6738, 6761, 6784, 6807, 
	6829, 6852, 6875, 6898, 6921, 6944, 6967, 6990, 7013, 7037, 7060, 7083, 7107, 7130, 
	7154, 7177, 7201, 7224, 7248, 7272, 7296, 7319, 7343, 7367, 7391, 7415, 7439, 7463, 
	7488, 7512, 7536, 7561, 7585, 7609, 7634, 7658, 7683, 7708, 7732, 7757, 7782, 7807, 
	7832, 7856, 7881, 7907, 7932, 7957, 7982, 8007, 8033, 8058, 8083, 8109, 8134, 8160, 
	8185, 8211, 8237, 8263, 8288, 8314, 8340, 8366, 8392, 8418, 8444, 8471, 8497, 8523, 
	8549, 8576, 8602, 8629, 8655, 8682, 8709, 8735, 8762, 8789, 8816, 8843, 8870, 8897, 
	8924, 8951, 8978, 9005, 9032, 9060, 9087, 9115, 9142, 9170, 9197, 9225, 9253, 9280, 
	9308, 9336, 9364, 9392, 9420, 9448, 9476, 9504, 9533, 9561, 9589, 9618, 9646, 9675, 
	9703, 9732, 9761, 9789, 9818, 9847, 9876, 9905, 9934, 9963, 9992, 10021, 10050, 10080, 
	10109, 10138, 10168, 10197, 10227, 10257, 10286, 10316, 10346, 10376, 10405, 10435, 10465, 
	10495, 10526, 10556, 10586, 10616, 10647, 10677, 10707, 10738, 10768, 10799, 10830, 10860, 
	10891, 10922, 10953, 10984, 11015, 11046, 11077, 11108, 11139, 11171, 11202, 11233, 11265, 
	11296, 11328, 11360, 11391, 11423, 11455, 11487, 11518, 11550, 11582, 11615, 11647, 11679, 
	11711, 11743, 11776, 11808, 11841, 11873, 11906, 11938, 11971, 12004, 12037, 12070, 12103, 
	12136, 12169, 12202, 12235, 12268, 12301, 12335, 12368, 12402, 12435, 12469, 12502, 12536, 
	12570, 12604, 12637, 12671, 12705, 12739, 12773, 12808, 12842, 12876, 12910, 12945, 12979, 
	13014, 13048, 13083, 13118, 13152, 13187, 13222, 13257, 13292, 13327, 13362, 13397, 13432, 
	13468, 13503, 13538, 13574, 13609, 13645, 13681, 13716, 13752, 13788, 13824, 13860, 13896, 
	13932, 13968, 14004, 14040, 14077, 14113, 14149, 14186, 14222, 14259, 14296, 14332, 14369, 
	14406, 14443, 14480, 14517, 14554, 14591, 14628, 14666, 14703, 14740, 14778, 14815, 14853, 
	14890, 14928, 14966, 15004, 15042, 15080, 15118, 15156, 15194, 15232, 15270, 15309, 15347, 
	15385, 15424, 15462, 15501, 15540, 15578, 15617, 15656, 15695, 15734, 15773, 15812, 15851, 
	15891, 15930, 15969, 16009, 16048, 16088, 16127, 16167, 16207, 16247, 16286, 16326, 16366, 
	16406, 16446, 16487, 16527, 16567, 16608, 16648, 16689, 16729, 16770, 16810, 16851, 16892, 
	16933, 16974, 17015, 17056, 17097, 17138, 17179, 17221, 17262, 17304, 17345, 17387, 17428, 
	17470, 17512, 17554, 17596, 17637, 17679, 17722, 17764, 17806, 17848, 17891, 17933, 17975, 
	18018, 18061, 18103, 18146, 18189, 18232, 18275, 18318, 18361, 18404, 18447, 18490, 18534, 
	18577, 18620, 18664, 18708, 18751, 18795, 18839, 18882, 18926, 18970, 19014, 19059, 19103, 
	19147, 19191, 19236, 19280, 19325, 19369, 19414, 19458, 19503, 19548, 19593, 19638, 19683, 
	19728, 19773, 19818, 19864, 19909, 19955, 20000, 
};

sl_pwm_instance_t sl_pwm_cold_lightness = {
  .timer = SL_PWM_PERIPHERAL_LT,
  .channel = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_CHANNEL),
  .port = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_PORT),
  .pin = (uint8_t)(SL_PWM_LIGHTNESS_OUTPUT_PIN),
};

sl_pwm_instance_t sl_pwm_warm_lightness = {
  .timer = SL_PWM_PERIPHERAL_CT,
  .channel = (uint8_t)(SL_PWM_CT_OUTPUT_CHANNEL),
  .port = (uint8_t)(SL_PWM_CT_OUTPUT_PORT),
  .pin = (uint8_t)(SL_PWM_CT_OUTPUT_PIN),
};
#endif

extern LightCurrentState *P_CdnLightNode;
extern uint8_t LightnessAndTempSyncChange;
extern LIGHT_EFFECT_CMD LightEffectCMD;

/*******************************************************************************
 * local data define
*******************************************************************************/
static uint8_t pwm_timer_start_flag = false;
static uint8_t pwm_ct_timer_start_flag = false;
static uint8_t pwm_rgb_timer_start_flag = false;

/*******************************************************************************
 * local function define
*******************************************************************************/


/*******************************************************************************
 * set_pwm_timer_start_flag
 * get_pwm_timer_start_flag
 * 设置和获取pwm timer开始停止标志
*******************************************************************************/
void set_pwm_timer_start_flag(uint8_t flag)
{
  pwm_timer_start_flag = flag;
}

uint8_t get_pwm_timer_start_flag(void)
{
  return pwm_timer_start_flag;
}

void set_pwm_ct_timer_start_flag(uint8_t flag)
{
  pwm_ct_timer_start_flag = flag;
}

uint8_t get_pwm_ct_timer_start_flag(void)
{
  return pwm_ct_timer_start_flag;
}

void set_pwm_rgb_timer_start_flag(uint8_t flag)
{
	pwm_rgb_timer_start_flag = flag;
}

uint8_t get_pwm_rgb_timer_start_flag(void)
{
	return pwm_rgb_timer_start_flag;
}
/*******************************************************************************
 * cdn_sl_pwm_init_instances
 * PWM初始化
*******************************************************************************/
void cdn_sl_pwm_init_instances(void)
{
#if CDN_LIGHT_BULB
  sl_pwm_config_t pwm_lightness_config = {
    .frequency = SL_PWM_CDN_PWM_LIGHTNESS_FREQUENCY,
    .polarity = SL_PWM_CDN_PWM_POLARITY_HIGH,
  };

  sl_pwm_init(&sl_pwm_lightness, &pwm_lightness_config);

	sl_pwm_config_t pwm_ct_config = {
    .frequency = SL_PWM_CDN_PWM_CT_FREQUENCY,
    .polarity = SL_PWM_CDN_PWM_POLARITY_HIGH,
  };

  sl_pwm_init(&sl_pwm_ct, &pwm_ct_config);
#elif CDN_LIGHT_STRIP
  sl_pwm_config_t pwm_cold_config = {
    .frequency = SL_PWM_CDN_PWM_LIGHTNESS_FREQUENCY,
    .polarity = SL_PWM_CDN_PWM_POLARITY_HIGH,
  };

  sl_pwm_init(&sl_pwm_cold_lightness, &pwm_cold_config);

  sl_pwm_config_t pwm_warm_config = {
    .frequency = SL_PWM_CDN_PWM_LIGHTNESS_FREQUENCY,
    .polarity = SL_PWM_CDN_PWM_POLARITY_LOW,
  };

  cdn_sl_pwm_init(&sl_pwm_warm_lightness, &pwm_warm_config);
#endif
}


/*******************************************************************************
 * CdnDimPwmStart
 * 启动Dim PWM
*******************************************************************************/
void CdnDimPwmStart(void)
{
#if CDN_LIGHT_BULB
  // Enable DIM PWM output
  sl_pwm_start(&sl_pwm_lightness);
#elif CDN_LIGHT_STRIP
  sl_pwm_start(&sl_pwm_warm_lightness);
#endif
}


/*******************************************************************************
 * CdnCtPwmStart
 * 启动CT PWM
*******************************************************************************/
void CdnCtPwmStart(void)
{
#if CDN_LIGHT_BULB
  // Enable CT PWM output
  sl_pwm_start(&sl_pwm_ct);
#elif CDN_LIGHT_STRIP
  sl_pwm_start(&sl_pwm_cold_lightness);
#endif
}


/*******************************************************************************
 * GeneralLightnessCtrl
 * @param percent 0-100
 * 设置pwm占空比
*******************************************************************************/
void GeneralLightnessCtrl(uint8_t percent)
{
#if CDN_LIGHT_BULB

  uint8_t Newpercent;
#if(CDN_MAX_POWER_12W_24W)
    {
      Newpercent = (percent*GetLightCurrentValue())/CDN_24W_Max_Cur;
    }
#else
    {
      Newpercent = (percent*GetLightCurrentValue())/CDN_12W_Max_Cur;
    }
#endif
  GeneralLightnessSetPercent(&sl_pwm_lightness, Newpercent);
  GeneralLightnessSetPercent(&sl_pwm_ct, GetCurrentCTvalue());//色温即显示当前色温值
#elif CDN_LIGHT_STRIP
  if(PWM_MAX_DUTY_CYCLE == percent)
  {
    CdnLightStripCtrlRepeat(percent, PWM_MAX_DUTY_CYCLE - percent);
  }
  else if(PWM_MIN_DUTY_CYCLE == percent)
  {
    CdnLightStripCtrlRepeat(percent, percent);
  }
#endif
}


/*******************************************************************************
 * GeneralLightnessSetDutycycle
 * @param pwm PWM指针
 * @param percent 占空比(0-100)
 * 此函数用于设置相应PWM的占空比
*******************************************************************************/
void GeneralLightnessSetPercent(sl_pwm_instance_t *pwm, uint8_t percent)
{
  sl_pwm_set_duty_cycle(pwm, percent);
}


#if CDN_LIGHT_BULB
/*******************************************************************************
 * DimChangePwmFreq
 * @param PwmFreq 频率
 * 改变pwm 频率，重新初始化pwm方式
*******************************************************************************/
void DimChangePwmFreq(uint32_t PwmFreq)
{
  sl_pwm_config_t pwm_CdnLightDimPwm_config = {
    .frequency = PwmFreq,
    .polarity = SL_PWM_CDN_PWM_POLARITY_HIGH,
  };

  sl_pwm_init(&sl_pwm_lightness, &pwm_CdnLightDimPwm_config);
}


/*******************************************************************************
 * cdn_dim_pwm_set_frequncy
 * @param pwm 指向pwm结构体的指针
 * @param top 数组频率值
 * 设置dim pwm频率，直接操作寄存器
*******************************************************************************/
void cdn_dim_pwm_set_frequncy(sl_pwm_instance_t *pwm, uint32_t top)
{
  // Set top value buffer
  TIMER_TopBufSet(pwm->timer, top);
}


/*******************************************************************************
 * cdn_pwm_set_duty_cycle
 * @param pwm 指向pwm结构体的指针
 * @param duty 数组占空比值
 * 设置pwm占空比，直接操作寄存器
*******************************************************************************/
void cdn_pwm_set_duty_cycle(sl_pwm_instance_t *pwm, uint32_t duty)
{
  // Set compare value
  TIMER_CompareBufSet(pwm->timer, pwm->channel, duty);
}


/*******************************************************************************
 * DimLightnessCtrl
 * @param percent 灯亮度值百分比
 * 调节灯的亮度值
*******************************************************************************/
void DimLightnessCtrl(uint8_t percent)
{
  uint16_t DutyIndex = percent * (DIM_MAX_VALUE_INDEX/PWM_MAX_DUTY_CYCLE);
  static uint16_t PreDutyIndex = 0;

  if((DutyIndex >= DIM_MAX_VALUE_INDEX || PreDutyIndex == DutyIndex)&&GetCurrentLightPowerWorkModeValue() == GetCurrentLightPrePowerWorkModeValue())
  {
    return;
  }
  TRACE("DimLightnessCtrl PWM percent = %d \r\n",percent);
  TRACE("DimLightnessCtrl PrePWM DutyIndex = %d \r\n",PreDutyIndex);
  TRACE("DimLightnessCtrl PWM DutyIndex = %d \r\n",DutyIndex);

  static uint16_t NewIndex = 0;

  if(GetCurrentLightPowerWorkModeValue()!=GetCurrentLightPrePowerWorkModeValue())
    {
      TRACE("lj: GetCurrentLightPowerWorkModeValue:%d\n",GetCurrentLightPowerWorkModeValue());
      SetCurrentLightPrePowerWorkModeValue(GetCurrentLightPowerWorkModeValue());
    }

  NewIndex = (DutyIndex*GetCurrentLightPowerWorkModeValue())/(DIM_MAX_VALUE_INDEX-1);
  //设置频率
  cdn_dim_pwm_set_frequncy(&sl_pwm_lightness, cdn_pwm_freq[NewIndex]);
  TRACE("zx: set dim pwm freq = %ld\n",cdn_pwm_freq[NewIndex]);
  //设置占空比
  cdn_pwm_set_duty_cycle(&sl_pwm_lightness, cdn_pwm_duty[NewIndex]);
  TRACE("zx: set dim pwm present = %ld\n",cdn_pwm_duty[NewIndex]);

  PreDutyIndex = DutyIndex;
}


/*******************************************************************************
 * DimLightnessCtrl
 * @param percent 灯色温值百分比
 * 调节灯的色温值，色温不用设置频率
*******************************************************************************/
void CtLightnessCtrl(uint8_t percent)
{
  uint16_t DutyIndex = percent*(DIM_MAX_VALUE_INDEX/PWM_MAX_DUTY_CYCLE);
  static uint16_t PreDutyIndex = 0;

  if(DutyIndex >= DIM_MAX_VALUE_INDEX || PreDutyIndex == DutyIndex)
  {
    return;
  }

  TRACE("CTLightnessCtrl PrePWM DutyIndex = %d \r\n",PreDutyIndex);
  TRACE("CTLightnessCtrl PWM DutyIndex = %d \r\n",DutyIndex);

  //设置占空比
  cdn_pwm_set_duty_cycle(&sl_pwm_ct, cdn_pwm_ct_duty[DutyIndex]);
  TRACE("zx: set CT pwm present = %ld\n",cdn_pwm_ct_duty[DutyIndex]);

  PreDutyIndex = DutyIndex;
}


/*******************************************************************************
 * DimLightnessFadeCtrl
 * @param index 亮度数组取值index(0-1000)
 * 渐变亮度调用函数
*******************************************************************************/
void DimLightnessFadeCtrl(uint16_t index)
{
  static uint16_t PreIndex = 0;

  if(index >= DIM_MAX_VALUE_INDEX || PreIndex == index)
  {
    return;
  }

  if(index == 0)
  {
    SetLedState(CDN_LED_OFF,0,0);
  }
  else
  {
      static uint16_t NewIndex = 0;
      NewIndex = (index*GetCurrentLightPowerWorkModeValue())/(DIM_MAX_VALUE_INDEX-1);
      //设置频率
      cdn_dim_pwm_set_frequncy(&sl_pwm_lightness, cdn_pwm_freq[NewIndex]);
      //设置占空比
      cdn_pwm_set_duty_cycle(&sl_pwm_lightness, cdn_pwm_duty[NewIndex]);
  }
  PreIndex = index;
}


/*******************************************************************************
 * CTLightnessFadeCtrl
 * @param index 色温数组取值index(0-1000)
 * 渐变色温调用函数，色温不用设置频率，频率跟亮度一起设置
*******************************************************************************/
void CTLightnessFadeCtrl(uint16_t index)
{
  static uint16_t PreIndex = 0;

  if(index >= DIM_MAX_VALUE_INDEX || PreIndex == index)
  {
    return;
  }

  //设置占空比
  cdn_pwm_set_duty_cycle(&sl_pwm_ct, cdn_pwm_ct_duty[index]);

  PreIndex = index;
}

void LightnessENHandle(void)
{
  uint8_t PreEnState;
  PreEnState = GPIO_PinInGet(CDN_EN_PORT, CDN_EN_PIN);
  //CdnLedState LightCurrentState = GetLedState().LightState;
  if(GetProvisionFlag() == 1)
    {
      if(GetLightState()==CDN_LED_IDLE||GetLightState()==CDN_DIM_CT_LED_ON)
        {
    //      if(PreEnState == 1&&(GetCurrentBrightness() == 0||GetTargetBrightness() == 0))
          if(PreEnState == 1&&CdnLightNode.GroupLightOnOff == 0)
            {
              GPIO_PinModeSet(CDN_EN_PORT, CDN_EN_PIN, gpioModePushPull, 0);
            }
    //      if(PreEnState == 0&&GetCurrentBrightness() > 0)
          if(PreEnState == 0&&CdnLightNode.GroupLightOnOff == 1)
            {
              GPIO_PinModeSet(CDN_EN_PORT, CDN_EN_PIN, gpioModePushPull, 1);
            }
        }
      else
        {
          //GPIO_PinModeSet(CDN_EN_PORT, CDN_EN_PIN, gpioModePushPull, 1);
        }
    }
}

/*******************************************************************************
 * CdnLightnessProcessActionForBulb
 * PWM Lightness 1ms定时器回调函数
*******************************************************************************/
void CdnLightnessProcessActionForBulb(void)
{
  if(true == get_pwm_timer_start_flag())
  {
    //渐变调光
    if(GetBrightnessRemainTime() != 0)
    {
      if(0 == P_CdnLightNode->DimRemainTime % LIGHT_ADJUST_INTERVAL)//10ms
      {
        if(1 == P_CdnLightNode->DimFadeFlag)
        {
          if(LightnessAndTempSyncChange == 1)
          {
						if(P_CdnLightNode->DimIndex < 1000){
            	P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX_X2;
						}
						else{
							P_CdnLightNode->DimIndex = 1000;
						}
          }
          else
          {
              if(GetGroupOnoffJudgeFlag())
                {
                  if(P_CdnLightNode->DimIndex < 1000){
                    P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX_X2;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 1000;
                  }
                }
              else
                {
                  if(P_CdnLightNode->DimIndex < 1000){
                    P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 1000;
                  }
                }
          }
          DimLightnessFadeCtrl(P_CdnLightNode->DimIndex);
        }
        else if(0 == P_CdnLightNode->DimFadeFlag)
        {
          if(LightnessAndTempSyncChange == 1)
          {
						if(P_CdnLightNode->DimIndex >= 4){
            	P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX_X2;
						}
						else{
							P_CdnLightNode->DimIndex = 0;
						}
          }
          else
          {
              if(GetGroupOnoffJudgeFlag())
                {
                  if(P_CdnLightNode->DimIndex >= 4){
                    P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX_X2;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 0;
                  }
                }
              else
                {
                  if(P_CdnLightNode->DimIndex >= 2){
                    P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 0;
                  }
                }
          }
          DimLightnessFadeCtrl(P_CdnLightNode->DimIndex);
        }

        if(P_CdnLightNode->DimIndex != 0)
        {
          SetCurrentBrightness(P_CdnLightNode->DimIndex / 10);
					P_CdnLightNode->DimEndIndex = P_CdnLightNode->DimIndex % 10;
          //长按调光调到最大或最小反馈给开关
          static uint8_t boradcase_cnt = 0;
          if((PWM_MAX_DUTY_CYCLE == P_CdnLightNode->DimIndex / 10) || (PWM_MIN_DUTY_CYCLE == P_CdnLightNode->DimIndex / 10)){
						if(boradcase_cnt ++ == 1)
						{
							//TRACE("zx: dimming broadcase!!!\n");
						}
          }
					else{
						boradcase_cnt = 0;
					}
        }
				else
				{
					SetCurrentBrightness(0);
					P_CdnLightNode->DimEndIndex = 0;
				}
      }
			P_CdnLightNode->DimRemainTime--;

			//如果当前亮度值等于目标亮度值且不等于0和100，则立即停止渐变
		  if((GetCurrentBrightness() == GetTargetBrightness()) && 
				 (GetCurrentBrightness() != PWM_MIN_DUTY_CYCLE) &&
				 (GetCurrentBrightness() != PWM_MAX_DUTY_CYCLE))
			{
				TRACE("zx: set_dim_remain_time = 0\n");
				P_CdnLightNode->DimRemainTime = 0;
			}
    }

    if(GetBrightnessRemainTime() == 0)
    {
      set_pwm_timer_start_flag(false);
      //显示当前亮度和色温
      SetLedState(CDN_DIM_CT_LED_ON,GetCurrentBrightness(),GetCurrentCTvalue());
      set_pwm_ct_timer_start_flag(true);
    }
  }
  else
  {
    return;
  }
}


/*******************************************************************************
 * CdnCTProcessActionForBulb
 * PWM CT 1ms定时器回调函数
*******************************************************************************/
void CdnColortempProcessActionForBulb(void)
{
  if(get_pwm_ct_timer_start_flag() == true)
  {
    if(GetCTRemainTime() != 0)
    {
      if(GetBrightnessRemainTime() == 0)
      {
        if(0 == P_CdnLightNode->CTRemainTime % LIGHT_ADJUST_INTERVAL)
        {
          if(1 == P_CdnLightNode->CTFadeFlag)
          {
            if(LightnessAndTempSyncChange == 1)
            {
							if(P_CdnLightNode->CTIndex < 1000){
              	P_CdnLightNode->CTIndex += LIGHT_ADJUST_INDEX_X2;
							}
							else{
								P_CdnLightNode->CTIndex = 1000;
							}
            }
            else
            {
							if(P_CdnLightNode->CTIndex < 1000){
              	P_CdnLightNode->CTIndex += LIGHT_ADJUST_INDEX;
							}
							else{
								P_CdnLightNode->CTIndex = 1000;
							}
            }
            CTLightnessFadeCtrl(P_CdnLightNode->CTIndex);
          }
          else if(0 == P_CdnLightNode->CTFadeFlag)
          {
            if(LightnessAndTempSyncChange == 1)
            {
							if(P_CdnLightNode->CTIndex >= 4){
              	P_CdnLightNode->CTIndex -= LIGHT_ADJUST_INDEX_X2;
							}
							else{
								P_CdnLightNode->CTIndex = 0;
							}
            }
            else
            {
							if(P_CdnLightNode->CTIndex >= 2){
              	P_CdnLightNode->CTIndex -= LIGHT_ADJUST_INDEX;
							}
							else{
								P_CdnLightNode->CTIndex = 0;
							}
            }
            CTLightnessFadeCtrl(P_CdnLightNode->CTIndex);
          }

          if(P_CdnLightNode->CTIndex != 0)
          {
            SetCurrentCTvalue(P_CdnLightNode->CTIndex / 10);
						P_CdnLightNode->CTEndIndex = P_CdnLightNode->CTIndex % 10;
          }
					else
					{
						SetCurrentCTvalue(0);
						P_CdnLightNode->CTEndIndex = 0;
					}
        }
        P_CdnLightNode->CTRemainTime--;

				//如果当前色温值等于目标色温值且不等于0和100，则立即停止渐变
			  if((GetCurrentCTvalue() == GetTargetCTvalue()) && 
					 (GetCurrentCTvalue() != PWM_MIN_DUTY_CYCLE) &&
					 (GetCurrentCTvalue() != PWM_MAX_DUTY_CYCLE))
				{
					TRACE("zx: set_ct_remain_time = 0\n");
					P_CdnLightNode->CTRemainTime = 0;
				}
      }
    }
    else
    {
	    set_pwm_ct_timer_start_flag(false);
      SetLedState(CDN_DIM_CT_LED_ON,GetCurrentBrightness(),GetCurrentCTvalue());
    }
  }
  else
  {
    return;
  }
}

/*******************************************************************************
 * CDN_Light_Breath_effect
 * 设置呼吸灯效
*******************************************************************************/
void CDN_Light_Breath_effect(void)
{
	static uint16_t BreathCnt = 0;
	static uint8_t BreathLightness = 0;
	static uint8_t BreathCmd = BREATH_UP;
	static uint8_t BreathTime = 0;

	BreathCnt ++;
	if(BreathCnt < 1000)
	{
		BreathCmd = BREATH_UP;
	}
	else if(BreathCnt >= 1000 && BreathCnt < 1000*2)
	{
		BreathCmd = BREATH_DOWN;
	}
	else
	{
		BreathCmd = BREATH_OVER;
		BreathCnt = 0;
		BreathTime ++;
		if(BreathTime == LightEffectCMD.time)
		{
			Set_CDN_Light_effect_mode(EFFECT_NONE, 0);
			BreathTime = 0;
		}
	}

	if(BREATH_UP == BreathCmd)
	{
		if(BreathCnt % 10 == 0)
		{
			BreathLightness ++;
			if(BreathLightness >= PWM_MAX_DUTY_CYCLE)
			{
				BreathLightness = PWM_MAX_DUTY_CYCLE;
			}

  uint8_t NewBreathLightness;
#if(CDN_MAX_POWER_12W_24W)
    {
    switch(GetCurrentLightPowerWorkMode())
    {
      case Power_15W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_1_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_18W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_2_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_20W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_3_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_24W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_4_Cur)/CDN_24W_Max_Cur;
        break;
      default:
        NewBreathLightness = (BreathLightness*CDN_24W_Min_Cur)/CDN_24W_Max_Cur;
        break;
    }
    }
#else
    {
      switch(GetCurrentLightPowerWorkMode())
      {
        case Power_5W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_1_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_7W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_2_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_9W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_3_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_12W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_4_Cur)/CDN_12W_Max_Cur;
          break;
        default:
          NewBreathLightness = (BreathLightness*CDN_12W_Min_Cur)/CDN_12W_Max_Cur;
          break;
      }
    }
#endif
    sl_pwm_set_duty_cycle(&sl_pwm_lightness, NewBreathLightness);
		}
	}
	else if(BreathCmd == BREATH_DOWN)
	{
		if(BreathCnt % 10 == 0)
		{
			if(BreathLightness > PWM_MIN_DUTY_CYCLE)
			{
				BreathLightness --;
			}
  uint8_t NewBreathLightness;
#if(CDN_MAX_POWER_12W_24W)
    {
    switch(GetCurrentLightPowerWorkMode())
    {
      case Power_15W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_1_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_18W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_2_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_20W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_3_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_24W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_4_Cur)/CDN_24W_Max_Cur;
        break;
      default:
        NewBreathLightness = (BreathLightness*CDN_24W_Min_Cur)/CDN_24W_Max_Cur;
        break;
    }
    }
#else
    {
      switch(GetCurrentLightPowerWorkMode())
      {
        case Power_5W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_1_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_7W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_2_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_9W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_3_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_12W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_4_Cur)/CDN_12W_Max_Cur;
          break;
        default:
          NewBreathLightness = (BreathLightness*CDN_12W_Min_Cur)/CDN_12W_Max_Cur;
          break;
      }
    }
#endif
    sl_pwm_set_duty_cycle(&sl_pwm_lightness, NewBreathLightness);
		}
	}
}


/*******************************************************************************
 * CDN_Light_Breath_effect
 * 设置呼吸灯效
*******************************************************************************/
void CDN_Light_Quick_Breath_effect(void)
{
	static uint16_t BreathCnt = 0;
	static uint8_t BreathLightness = 0;
	static uint8_t BreathCmd = BREATH_UP;
	static uint8_t BreathTime = 0;

	BreathCnt ++;
	if(BreathCnt < 500)
	{
		BreathCmd = BREATH_UP;
	}
	else if(BreathCnt >= 500 && BreathCnt < 500*2)
	{
		BreathCmd = BREATH_DOWN;
	}
	else
	{
		BreathCmd = BREATH_OVER;
		BreathCnt = 0;
		BreathTime ++;
		if(BreathTime == LightEffectCMD.time)
		{
			Set_CDN_Light_effect_mode(EFFECT_NONE, 0);
			BreathTime = 0;
			sl_btmesh_initiate_node_reset();
		}
	}

	if(BREATH_UP == BreathCmd)
	{
		if(BreathCnt % 5 == 0)
		{
			BreathLightness ++;
			if(BreathLightness >= PWM_MAX_DUTY_CYCLE)
			{
				BreathLightness = PWM_MAX_DUTY_CYCLE;
			}
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
  uint8_t NewBreathLightness;
#if(CDN_MAX_POWER_12W_24W)
    {
    switch(GetCurrentLightPowerWorkMode())
    {
      case Power_15W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_1_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_18W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_2_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_20W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_3_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_24W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_4_Cur)/CDN_24W_Max_Cur;
        break;
      default:
        NewBreathLightness = (BreathLightness*CDN_24W_Min_Cur)/CDN_24W_Max_Cur;
        break;
    }
    }
#else
    {
      switch(GetCurrentLightPowerWorkMode())
      {
        case Power_5W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_1_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_7W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_2_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_9W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_3_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_12W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_4_Cur)/CDN_12W_Max_Cur;
          break;
        default:
          NewBreathLightness = (BreathLightness*CDN_12W_Min_Cur)/CDN_12W_Max_Cur;
          break;
      }
    }
#endif
    sl_pwm_set_duty_cycle(&sl_pwm_lightness, NewBreathLightness);
		}
	}
	else if(BreathCmd == BREATH_DOWN)
	{
		if(BreathCnt % 5 == 0)
		{
			if(BreathLightness > PWM_MIN_DUTY_CYCLE)
			{
				BreathLightness --;
			}
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
  uint8_t NewBreathLightness;
#if(CDN_MAX_POWER_12W_24W)
    {
    switch(GetCurrentLightPowerWorkMode())
    {
      case Power_15W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_1_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_18W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_2_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_20W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_3_Cur)/CDN_24W_Max_Cur;
        break;
      case Power_24W_Mode:
        NewBreathLightness = (BreathLightness*CDN_24W_4_Cur)/CDN_24W_Max_Cur;
        break;
      default:
        NewBreathLightness = (BreathLightness*CDN_24W_Min_Cur)/CDN_24W_Max_Cur;
        break;
    }
    }
#else
    {
      switch(GetCurrentLightPowerWorkMode())
      {
        case Power_5W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_1_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_7W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_2_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_9W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_3_Cur)/CDN_12W_Max_Cur;
          break;
        case Power_12W_Mode:
          NewBreathLightness = (BreathLightness*CDN_12W_4_Cur)/CDN_12W_Max_Cur;
          break;
        default:
          NewBreathLightness = (BreathLightness*CDN_12W_Min_Cur)/CDN_12W_Max_Cur;
          break;
      }
    }
#endif
    sl_pwm_set_duty_cycle(&sl_pwm_lightness, NewBreathLightness);
		}
	}
}

#elif CDN_LIGHT_STRIP
/*******************************************************************************
 * GeneralLightnessSetDutycycle
 * @param pwm PWM指针
 * @param duty 占空比,直接设置寄存器
 * 此函数用于设置相应PWM的占空比
*******************************************************************************/
void GeneralLightnessSetDutycycle(sl_pwm_instance_t *pwm, uint32_t duty)
{
  TIMER_CompareBufSet(pwm->timer, pwm->channel, duty);
}


/*******************************************************************************
 * CdnLightScripCtrlRepeat
 * @param Lightness 亮度值(0-100)
 * @param Temp 色温值(0-100)
 * 此函数利用公式计算相应的CW值，重复执行的情况调用次函数
*******************************************************************************/
void CdnLightStripCtrlRepeat(uint8_t Lightness,uint8_t Temp)
{
  uint32_t Cold = 0;
  uint32_t Warm = 0;
  static uint16_t PreLightness = 50;

  if(Lightness > PWM_MAX_DUTY_CYCLE || PreLightness == Lightness || Temp > PWM_MAX_DUTY_CYCLE)
  {
    return;
  }

  TRACE("DimLightnessCtrl PWM Lightness = %d \r\n",Lightness);
  TRACE("DimLightnessCtrl PrePWM Lightness = %d \r\n",PreLightness);

  uint32_t Lightness_Value = cdn_pwm_duty[Lightness * 10];
  uint32_t Temp_Value = cdn_pwm_duty[Temp * 10];

  //CW互补模式公式计算如下，C极性设置为HIGH，W极性设置为LOW
  Cold = (Lightness_Value * Temp_Value) / DIM_MAX_VALUE;
  Warm = DIM_MAX_VALUE - ((Lightness_Value * (DIM_MAX_VALUE - Temp_Value)) / DIM_MAX_VALUE);

  //TRACE("zx: CdnLightScripCtrlRepeat Lightness = %d,Temp = %d,Cold = %d,Warm = %d\n",Lightness,Temp,Cold,Warm);

  GeneralLightnessSetDutycycle(&sl_pwm_cold_lightness, Cold);
  GeneralLightnessSetDutycycle(&sl_pwm_warm_lightness, Warm);

  PreLightness = Lightness;
}


/*******************************************************************************
 * CdnLightStripColorTempCtrl
 * @param Lightness 亮度值(0-5000)
 * @param Temp 色温值(0-20000)
 * 此函数利用公式计算相应的CW值
*******************************************************************************/
void CdnLightStripColorTempCtrl(uint32_t Lightness,uint32_t Temp)
{
  uint32_t Cold = 0;
  uint32_t Warm = 0;

  //CW互补模式公式计算如下，C极性设置为HIGH，W极性设置为LOW
  Cold = (Lightness * Temp) / DIM_MAX_VALUE;
  Warm = DIM_MAX_VALUE - ((Lightness * (DIM_MAX_VALUE - Temp)) / DIM_MAX_VALUE);

  //TRACE("zx: CdnLightScripColorTempCtrl Lightness = %d,Temp = %d,Cold = %d,Warm = %d\n",Lightness,Temp,Cold,Warm);

  GeneralLightnessSetDutycycle(&sl_pwm_cold_lightness, Cold);
  GeneralLightnessSetDutycycle(&sl_pwm_warm_lightness, Warm);
}


/*******************************************************************************
 * CdnLightStripColorTempCtrl
 * @param index 灯带调光曲线取值(0-1000)
 * 此函数用于取出亮度占空比值
*******************************************************************************/
void CdnStripLightnessSetIndex(uint16_t index)
{
	//TRACE("zx: CdnStripLightnessSetIndex CTIndex:%d DimIndex:%d\n",P_CdnLightNode->CTIndex,index);
	if(index >= DIM_MAX_VALUE_INDEX){
		TRACE("CdnStripLightnessSetIndex Error!!!\n");
		return;
	}
  CdnLightStripColorTempCtrl(cdn_pwm_duty[index], cdn_pwm_duty[P_CdnLightNode->CTIndex]);
}


/*******************************************************************************
 * CdnStripTempSetIndex
 * @param index 灯带调光曲线取值(0-1000)
 * 此函数用于取出色温占空比值
*******************************************************************************/
void CdnStripTempSetIndex(uint16_t index)
{
	//TRACE("zx: CdnStripTempSetIndex CTIndex:%d DimIndex:%d-%d\n",index,P_CdnLightNode->DimIndex,GetCurrentBrightness() * 10);
	if(index >= DIM_MAX_VALUE_INDEX){
		TRACE("CdnStripTempSetIndex Error!!!\n");
		return;
	}
  CdnLightStripColorTempCtrl(cdn_pwm_duty[P_CdnLightNode->DimIndex], cdn_pwm_duty[index]);
}


/*******************************************************************************
 * CdnLightnessProcessActionForStrip
 * PWM Lightness 1ms定时器回调函数
*******************************************************************************/
void CdnLightnessProcessActionForStrip(void)
{
  if(true == get_pwm_timer_start_flag())
  {
    if(GetBrightnessRemainTime() != 0)
    {
      if(0 == P_CdnLightNode->DimRemainTime % LIGHT_ADJUST_INTERVAL)//10ms
      {
        if(1 == P_CdnLightNode->DimFadeFlag)
        {
          if(LightnessAndTempSyncChange == 1)
          {
						if(P_CdnLightNode->DimIndex < 1000){
            	P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX_X2;
						}
						else{
							P_CdnLightNode->DimIndex = 1000;
						}
          }
          else
          {
              if(GetGroupOnoffJudgeFlag())
                {
                  if(P_CdnLightNode->DimIndex < 1000){
                    P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX_X2;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 1000;
                  }
                }
              else
                {
                  if(P_CdnLightNode->DimIndex < 1000){
                    P_CdnLightNode->DimIndex += LIGHT_ADJUST_INDEX;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 1000;
                  }
                }
          }
          CdnStripLightnessSetIndex(P_CdnLightNode->DimIndex);
        }
        else if(0 == P_CdnLightNode->DimFadeFlag)
        {
          if(LightnessAndTempSyncChange == 1)
          {
						if(P_CdnLightNode->DimIndex >= 4){
            	P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX_X2;
						}
						else{
							P_CdnLightNode->DimIndex = 0;
						}
          }
          else
          {
              if(GetGroupOnoffJudgeFlag())
                {
                  if(P_CdnLightNode->DimIndex >= 4){
                    P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX_X2;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 0;
                  }
                }
              else
                {
                  if(P_CdnLightNode->DimIndex >= 2){
                    P_CdnLightNode->DimIndex -= LIGHT_ADJUST_INDEX;
                  }
                  else{
                    P_CdnLightNode->DimIndex = 0;
                  }
                }
          }
          CdnStripLightnessSetIndex(P_CdnLightNode->DimIndex);
        }

        if(P_CdnLightNode->DimIndex != 0)
        {
          SetCurrentBrightness(P_CdnLightNode->DimIndex / 10);
					P_CdnLightNode->DimEndIndex = P_CdnLightNode->DimIndex % 10;
        }
				else
				{
					SetCurrentBrightness(0);
					P_CdnLightNode->DimEndIndex = 0;
				}
      }
      P_CdnLightNode->DimRemainTime--;

			//如果当前亮度值等于目标亮度值且不等于0和100，则立即停止渐变
		  if((GetCurrentBrightness() == GetTargetBrightness()) && 
				 (GetCurrentBrightness() != PWM_MIN_DUTY_CYCLE) &&
				 (GetCurrentBrightness() != PWM_MAX_DUTY_CYCLE))
			{
				TRACE("zx: set_dim_remain_time = 0,DimIndex = %d\n",P_CdnLightNode->DimIndex);
				P_CdnLightNode->DimRemainTime = 0;
			}
    }

    if(GetBrightnessRemainTime() == 0)
    {
      set_pwm_timer_start_flag(false);
      SetLedState(CDN_DIM_CT_LED_ON,GetCurrentBrightness(),GetCurrentCTvalue());
#if CDN_STRIP_DIMMING_LIGHT
#else
      set_pwm_ct_timer_start_flag(true);
#endif
    }
  }
  else
  {
    return;
  }
}


/*******************************************************************************
 * CdnColortempProcessActionForStrip
 * PWM CT 1ms定时器回调函数
 * 问题：灯带同时调节亮度和色温会相互影响其CW计算公式，从而产生灯光的抖动
 * 解决对策：色温调节单独起一个timer，如果亮度和色温同时调节，则先进行亮度调节，
 * 再进行色温调节
*******************************************************************************/
void CdnColortempProcessActionForStrip(void)
{
  if(get_pwm_ct_timer_start_flag() == true)
  {
    if(GetCTRemainTime() != 0)
    {
      if(GetBrightnessRemainTime() == 0)
      {
        if(0 == P_CdnLightNode->CTRemainTime % LIGHT_ADJUST_INTERVAL)
        {
          if(1 == P_CdnLightNode->CTFadeFlag)
          {
            if(LightnessAndTempSyncChange == 1)
            {
							if(P_CdnLightNode->CTIndex < 1000){
              	P_CdnLightNode->CTIndex += LIGHT_ADJUST_INDEX_X2;
							}
							else{
								P_CdnLightNode->CTIndex = 1000;
							}
            }
            else
            {
							if(P_CdnLightNode->CTIndex < 1000){
              	P_CdnLightNode->CTIndex += LIGHT_ADJUST_INDEX;
							}
							else{
								P_CdnLightNode->CTIndex = 1000;
							}
            }
            CdnStripTempSetIndex(P_CdnLightNode->CTIndex);
          }
          else if(0 == P_CdnLightNode->CTFadeFlag)
          {
            if(LightnessAndTempSyncChange == 1)
            {
							if(P_CdnLightNode->CTIndex >= 4){
              	P_CdnLightNode->CTIndex -= LIGHT_ADJUST_INDEX_X2;
							}
							else{
								P_CdnLightNode->CTIndex = 0;
							}
            }
            else
            {
							if(P_CdnLightNode->CTIndex >= 2){
              	P_CdnLightNode->CTIndex -= LIGHT_ADJUST_INDEX;
							}
							else{
								P_CdnLightNode->CTIndex = 0;
							}
            }
            CdnStripTempSetIndex(P_CdnLightNode->CTIndex);
          }
					
          if(P_CdnLightNode->CTIndex != 0)
          {
            SetCurrentCTvalue(P_CdnLightNode->CTIndex / 10);
						P_CdnLightNode->CTEndIndex = P_CdnLightNode->CTIndex % 10;
          }
					else
					{
						SetCurrentCTvalue(0);
						P_CdnLightNode->CTEndIndex = 0;
					}
        }
        P_CdnLightNode->CTRemainTime--;

				//如果当前色温值等于目标色温值且不等于0和100，则立即停止渐变
			  if((GetCurrentCTvalue() == GetTargetCTvalue()) && 
					 (GetCurrentCTvalue() != PWM_MIN_DUTY_CYCLE) &&
					 (GetCurrentCTvalue() != PWM_MAX_DUTY_CYCLE))
				{
					TRACE("zx: set_ct_remain_time = 0,CTIndex = %d\n",P_CdnLightNode->CTIndex);
					P_CdnLightNode->CTRemainTime = 0;
				}
      }
    }
    else
    {
      set_pwm_ct_timer_start_flag(false);
      SetLedState(CDN_DIM_CT_LED_ON,GetCurrentBrightness(),GetCurrentCTvalue());
    }
  }
  else
  {
    return;
  }
}


/*******************************************************************************
 * CDN_Light_Breath_effect
 * 设置呼吸灯效
*******************************************************************************/
void CDN_Light_Breath_effect(void)
{
	static uint16_t BreathCnt = 0;
	static uint8_t BreathLightness = 0;
	static uint8_t BreathCmd = BREATH_UP;
	static uint8_t BreathTime = 0;
	static uint8_t Cold;
	static uint8_t Warm;

	BreathCnt ++;
	if(BreathCnt < 1000)
	{
		BreathCmd = BREATH_UP;
	}
	else if(BreathCnt >= 1000 && BreathCnt < 1000*2)
	{
		BreathCmd = BREATH_DOWN;
	}
	else
	{
		BreathCmd = BREATH_OVER;
		BreathCnt = 0;
		BreathTime ++;
		if(BreathTime == LightEffectCMD.time)
		{
			Set_CDN_Light_effect_mode(EFFECT_NONE, 0);
			BreathTime = 0;
		}
	}

	if(BREATH_UP == BreathCmd)
	{
		if(BreathCnt % 10 == 0)
		{
			BreathLightness ++;
			if(BreathLightness >= PWM_MAX_DUTY_CYCLE)
			{
				BreathLightness = PWM_MAX_DUTY_CYCLE;
			}

			Cold = (BreathLightness * 0) / 100;
			Warm = 100 - ((BreathLightness * (100 - 0)) / 100);

			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
			sl_pwm_set_duty_cycle(&sl_pwm_cold_lightness, Cold);
			sl_pwm_set_duty_cycle(&sl_pwm_warm_lightness, Warm);
		}
	}
	else if(BreathCmd == BREATH_DOWN)
	{
		if(BreathCnt % 10 == 0)
		{
			if(BreathLightness > PWM_MIN_DUTY_CYCLE)
			{
				BreathLightness --;
			}
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);

			Cold = (BreathLightness * 0) / 100;
			Warm = 100 - ((BreathLightness * (100 - 0)) / 100);
			
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
			sl_pwm_set_duty_cycle(&sl_pwm_cold_lightness, Cold);
			sl_pwm_set_duty_cycle(&sl_pwm_warm_lightness, Warm);
		}
	}
}


/*******************************************************************************
 * CDN_Light_Breath_effect
 * 设置呼吸灯效
*******************************************************************************/
void CDN_Light_Quick_Breath_effect(void)
{
	static uint16_t BreathCnt = 0;
	static uint8_t BreathLightness = 0;
	static uint8_t BreathCmd = BREATH_UP;
	static uint8_t BreathTime = 0;
	static uint8_t Cold;
	static uint8_t Warm;

	BreathCnt ++;
	if(BreathCnt < 500)
	{
		BreathCmd = BREATH_UP;
	}
	else if(BreathCnt >= 500 && BreathCnt < 500*2)
	{
		BreathCmd = BREATH_DOWN;
	}
	else
	{
		BreathCmd = BREATH_OVER;
		BreathCnt = 0;
		BreathTime ++;
		if(BreathTime == LightEffectCMD.time)
		{
			Set_CDN_Light_effect_mode(EFFECT_NONE, 0);
			BreathTime = 0;
			sl_btmesh_initiate_node_reset();
		}
	}

	if(BREATH_UP == BreathCmd)
	{
		if(BreathCnt % 5 == 0)
		{
			BreathLightness ++;
			if(BreathLightness >= PWM_MAX_DUTY_CYCLE)
			{
				BreathLightness = PWM_MAX_DUTY_CYCLE;
			}
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);

			Cold = (BreathLightness * 0) / 100;
			Warm = 100 - ((BreathLightness * (100 - 0)) / 100);
			
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
			sl_pwm_set_duty_cycle(&sl_pwm_cold_lightness, Cold);
			sl_pwm_set_duty_cycle(&sl_pwm_warm_lightness, Warm);
		}
	}
	else if(BreathCmd == BREATH_DOWN)
	{
		if(BreathCnt % 5 == 0)
		{
			if(BreathLightness > PWM_MIN_DUTY_CYCLE)
			{
				BreathLightness --;
			}
			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);

			Cold = (BreathLightness * 0) / 100;
			Warm = 100 - ((BreathLightness * (100 - 0)) / 100);

			//TRACE("zx: CDN_Light_Breath_effect BreathLightness = %d\n",BreathLightness);
			sl_pwm_set_duty_cycle(&sl_pwm_cold_lightness, Cold);
			sl_pwm_set_duty_cycle(&sl_pwm_warm_lightness, Warm);
		}
	}
}
#endif
